我想整天遷移我的localStorage數據到realm.io ... 現在唯一的問題是我現在面臨的是,我可以用Swift realm.io可以使用object.getValueForKey(「key」)獲取對象屬性,但不能作爲object.key
object.valueforKey("key")
獲取對象屬性,但不能使用簡單的一個
object.key
這裏有我的代碼和平
let realm = try! Realm()
let predicate = NSPredicate(format: "groupID = %@", group.valueForKey("groupID") as! String)
let current = realm.objects(apiGroup).filter(predicate)
let currentGroup = current[0]
print(currentGroup.valueForKey("token") as! String)
print(currentGroup.token)
當我執行,這已被打印在控制檯上。
56abbf408cfea7941a8b30b7
fatal error: unexpectedly found nil while unwrapping an Optional value
你能告訴我,如果這是正常的行爲,或者如果我可以做一些事情來獲得
「object.key」
符號?? 在此先感謝
爲什麼要投票?讓我知道可能是我的一個微不足道的錯誤可以是解決方案 –
我upvoted嘗試和阻止仇敵。 :)原因是'object.key'會與需要顯式定義的對象屬性有關。鑑於'object.valueForKey()'是iOS的一項名爲'鍵值編碼'的功能(https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/KeyValueCoding/Articles/KeyValueCoding.html)指定的鍵可能是也可能不是該對象的值。 – TiM
請發表它作爲答覆我會接受它 –