forked from objcio/core-data
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKeyCodable.swift
49 lines (37 loc) · 1.22 KB
/
KeyCodable.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//
// KeyCodable.swift
// Moody
//
// Created by Florian on 17/11/15.
// Copyright © 2015 objc.io. All rights reserved.
//
import CoreData
public protocol KeyCodable {
typealias Keys: RawRepresentable
}
extension KeyCodable where Self: ManagedObject, Keys.RawValue == String {
public func willAccessValueForKey(key: Keys) {
willAccessValueForKey(key.rawValue)
}
public func didAccessValueForKey(key: Keys) {
didAccessValueForKey(key.rawValue)
}
public func willChangeValueForKey(key: Keys) {
(self as ManagedObject).willChangeValueForKey(key.rawValue)
}
public func didChangeValueForKey(key: Keys) {
(self as ManagedObject).didChangeValueForKey(key.rawValue)
}
public func valueForKey(key: Keys) -> AnyObject? {
return (self as ManagedObject).valueForKey(key.rawValue)
}
public func mutableSetValueForKey(key: Keys) -> NSMutableSet {
return mutableSetValueForKey(key.rawValue)
}
public func changedValueForKey(key: Keys) -> AnyObject? {
return changedValues()[key.rawValue]
}
public func committedValueForKey(key: Keys) -> AnyObject? {
return committedValuesForKeys([key.rawValue])[key.rawValue]
}
}