OSDN Git Service
(root)
/
kcd
/
KCD.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Doutaku を 1.0 にアップデート
[kcd/KCD.git]
/
KCD
/
KCManagedObject.swift
diff --git
a/KCD/KCManagedObject.swift
b/KCD/KCManagedObject.swift
index
53a6cb6
..
e669ea4
100644
(file)
--- a/
KCD/KCManagedObject.swift
+++ b/
KCD/KCManagedObject.swift
@@
-8,12
+8,15
@@
import Foundation
import CoreData
import Foundation
import CoreData
+import Doutaku
enum KCManagedObjectError: Error {
enum KCManagedObjectError: Error {
+
case invalid
}
class KCManagedObject: NSManagedObject {
case invalid
}
class KCManagedObject: NSManagedObject {
+
private static let intValueKyes =
[
"api_enqflg", "api_aftershipid", "api_progress", "api_usebull",
private static let intValueKyes =
[
"api_enqflg", "api_aftershipid", "api_progress", "api_usebull",
@@
-23,43
+26,71
@@
class KCManagedObject: NSManagedObject {
"api_flag_5", "api_flag_6", "api_flag_7",
"api_level"
]
"api_flag_5", "api_flag_6", "api_flag_7",
"api_level"
]
+
override func validateValue(_ value: AutoreleasingUnsafeMutablePointer<AnyObject?>, forKey key: String) throws {
override func validateValue(_ value: AutoreleasingUnsafeMutablePointer<AnyObject?>, forKey key: String) throws {
+
if value.pointee is NSNull {
if value.pointee is NSNull {
+
value.pointee = nil
value.pointee = nil
+
return
}
return
}
+
if KCManagedObject.intValueKyes.contains(key) {
if KCManagedObject.intValueKyes.contains(key) {
- if let _ = value.pointee as? Int { return }
+
+ if let _ = value.pointee as? Int {
+
+ return
+ }
if let s = value.pointee as? String {
if let s = value.pointee as? String {
+
value.pointee = Int(s) as AnyObject?
value.pointee = Int(s) as AnyObject?
+
return
}
return
}
+
print("KCManagedObject type \(type(of: value.pointee))")
print("KCManagedObject type \(type(of: value.pointee))")
+
throw KCManagedObjectError.invalid
}
}
override func value(forUndefinedKey key: String) -> Any? {
throw KCManagedObjectError.invalid
}
}
override func value(forUndefinedKey key: String) -> Any? {
- if key == "description" { return value(forKey: "description_") }
+
+ if key == "description" {
+
+ return value(forKey: "description_")
+ }
+
if key.hasPrefix("api_") {
if key.hasPrefix("api_") {
- let four = key.index(key.startIndex, offsetBy: 4)
- let k = key[four..<key.endIndex]
+
+ let k = String(key[key.index(key.startIndex, offsetBy: 4)...])
+
return value(forKey: k)
}
return value(forKey: k)
}
- print("Entity \(entity.name) dose not have key \(key)")
+
+ print("Entity \(String(describing: self)) dose not have key \(key)")
+
return nil
}
return nil
}
+
override func setValue(_ value: Any?, forUndefinedKey key: String) {
override func setValue(_ value: Any?, forUndefinedKey key: String) {
+
if key == "description" {
if key == "description" {
+
setValue(value, forKey: "description_")
setValue(value, forKey: "description_")
+
return
}
return
}
+
if key.hasPrefix("api_") {
if key.hasPrefix("api_") {
- let four = key.index(key.startIndex, offsetBy: 4)
- let k =
key[four..<key.endIndex]
+
+ let k =
String(key[key.index(key.startIndex, offsetBy: 4)...])
setValue(value, forKey: k)
setValue(value, forKey: k)
+
return
}
return
}
- print("Entity \(entity.name) dose not have key \(key)")
+
+ print("Entity \(String(describing: self)) dose not have key \(key)")
}
}
}
}