parkhaneul
(parkhaneul)
1
KeyPath is PowerFull.
but, i needs keypath("") like #keypath("")
can it, i ease json-parsing like
struct a{
init(json : Dictionary<String,Any>){
for (key,value) in json{
self[keypath : key] = value
}
}
struct b : a{}
struct c : a{}
struct b,c is auto-mapping at jsonData.
can it?
For now the keypath concept is entirely static, meaning that you cannot translate a keypath to a string or a string to a keypath.
Have you looked at the Codable concepts for reading and writing to json?
Codable is extremely powerful and let’s you encode to and decode from json with very little code.
malhal
(Malcolm Hall)
3
I also hit this problem, I expected this to work:
let dict = NSMutableDictionary(object: "value1", forKey: NSString("key"))
dict.observe(keyPath:KeyPath("key")) { (dict, change) in // compilation error
print("changed")
}
dict.setObject("value2", forKey: NSString("key"))
'KeyPath<Root, Value>' cannot be constructed because it has no accessible initializers
1 Like