Adding in the changes to consider optionals when checking if the keyIsEmpty
This commit is contained in:
parent
f2f54fe2ef
commit
1cbb94d729
|
@ -1,18 +1,10 @@
|
||||||
//
|
// Generated automatically by Perfect Assistant Application
|
||||||
// Package.swift
|
// Date: 2017-08-13 18:42:55 +0000
|
||||||
// StORM
|
|
||||||
//
|
|
||||||
// Created by Jonathan Guthrie on 2016-09-23.
|
|
||||||
// Copyright (C) 2016 Jonathan Guthrie.
|
|
||||||
//
|
|
||||||
|
|
||||||
import PackageDescription
|
import PackageDescription
|
||||||
|
|
||||||
let package = Package(
|
let package = Package(
|
||||||
name: "StORM",
|
name: "StORM",
|
||||||
targets: [],
|
targets: [],
|
||||||
dependencies: [
|
dependencies: [
|
||||||
.Package(url: "https://github.com/PerfectlySoft/PerfectLib.git", majorVersion: 2)
|
.Package(url: "https://github.com/PerfectlySoft/PerfectLib.git", majorVersion: 2),
|
||||||
],
|
]
|
||||||
exclude: []
|
|
||||||
)
|
)
|
||||||
|
|
|
@ -103,19 +103,37 @@ open class StORM {
|
||||||
/// Returns a boolean that is true if the first property in the class contains a value.
|
/// Returns a boolean that is true if the first property in the class contains a value.
|
||||||
public func keyIsEmpty() -> Bool {
|
public func keyIsEmpty() -> Bool {
|
||||||
let (_, val) = firstAsKey()
|
let (_, val) = firstAsKey()
|
||||||
if val is Int {
|
|
||||||
if val as! Int == 0 {
|
// Grab the type of value:
|
||||||
return true
|
let type = type(of: val)
|
||||||
} else {
|
// Check if we are nil, we would then of course have an empty primary key.
|
||||||
return false
|
guard String(describing: val) != "nil" else {
|
||||||
}
|
return true
|
||||||
} else {
|
}
|
||||||
if (val as! String).isEmpty {
|
|
||||||
return true
|
switch type {
|
||||||
} else {
|
case is Int.Type, is Int?.Type:
|
||||||
return false
|
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
|
/// The create method is designed to be overridden
|
||||||
|
|
Loading…
Reference in New Issue