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 @@
// // 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: []
) )

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. /// 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:
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 return true
} else { }
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 return false
} }
} else {
if (val as! String).isEmpty { // if val is Int {
return true // if val as! Int == 0 {
} else { // return true
return false // } 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