Adding in the changes to consider optionals when checking if the keyIsEmpty

This commit is contained in:
Ryan Coyne 2017-08-13 14:51:52 -04:00
parent f2f54fe2ef
commit 1cbb94d729
2 changed files with 35 additions and 25 deletions

View File

@ -1,18 +1,10 @@
//
// Package.swift
// StORM
//
// Created by Jonathan Guthrie on 2016-09-23.
// Copyright (C) 2016 Jonathan Guthrie.
//
// Generated automatically by Perfect Assistant Application
// Date: 2017-08-13 18:42:55 +0000
import PackageDescription
let package = Package(
name: "StORM",
targets: [],
dependencies: [
.Package(url: "https://github.com/PerfectlySoft/PerfectLib.git", majorVersion: 2)
],
exclude: []
.Package(url: "https://github.com/PerfectlySoft/PerfectLib.git", majorVersion: 2),
]
)

View File

@ -103,19 +103,37 @@ open class StORM {
/// Returns a boolean that is true if the first property in the class contains a value.
public func keyIsEmpty() -> Bool {
let (_, val) = firstAsKey()
if val is Int {
if val as! Int == 0 {
return true
} else {
return false
}
} else {
if (val as! String).isEmpty {
return true
} else {
return false
}
}
// Grab the type of value:
let type = type(of: val)
// Check if we are nil, we would then of course have an empty primary key.
guard String(describing: val) != "nil" else {
return true
}
switch type {
case is Int.Type, is Int?.Type:
return (val as! Int == 0)
case is String.Type, is String?.Type:
return (val as! String).isEmpty
default:
print("[StORM] WARNING: Switched unexpected type for PRIMARY KEY in function: \(#function). TYPE: \(type)")
return false
}
// if val is Int {
// if val as! Int == 0 {
// return true
// } else {
// return false
// }
// } else {
// if (val as! String).isEmpty {
// return true
// } else {
// return false
// }
// }
}
/// The create method is designed to be overridden