-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathWOKeyPathAssociation.swift
More file actions
39 lines (30 loc) · 1017 Bytes
/
WOKeyPathAssociation.swift
File metadata and controls
39 lines (30 loc) · 1017 Bytes
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
//
// WOKeyPathAssociation.swift
// SwiftObjects
//
// Created by Helge Hess on 11.05.18.
// Copyright © 2018 ZeeZide. All rights reserved.
//
/**
* Evaluates a KVC keypath against the current component.
*/
public class WOKeyPathAssociation : WOAssociation, SmartDescription {
public let path : [ String ]
public init(_ path: String) {
self.path = path.components(separatedBy: ".")
}
public var keyPath: String? { return path.joined(separator: ".") }
public var isValueConstant : Bool { return false }
public var isValueSettable : Bool { return true }
public func setValue(_ value: Any?, in component: Any?) throws {
try KeyValueCoding.takeValue(value, forKeyPath: path, inObject: component)
}
public func value(in component: Any?) -> Any? {
return KeyValueCoding.value(forKeyPath: path, inObject: component)
}
// MARK: - Description
public func appendToDescription(_ ms: inout String) {
ms.append(" path=")
ms.append(keyPath ?? "-")
}
}