每次我尝试使用iCloud键值存储设置密钥值时,我的应用程序崩溃...
我收到此错误:
Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<NSUbiquitousKeyValueStore 0x13fd5b8a0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key ladies.'
*** First throw call stack:
(0x1842f0f48 0x19979bf80 0x1842f0c08 0x18516c014 0x1000e5380 0x1000e9914 0x1000f0430 0x1000f046c 0x1000f04a0 0x1000f04e4 0x1898bf240 0x1898bed3c 0x1898bebc4 0x189085c2c 0x101429c68 0x10142f710 0x1842a81f8 0x1842a6060 0x1841d4ca0 0x18f758088 0x1898ecffc 0x1000f4564 0x199fde8b8)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
Run Code Online (Sandbox Code Playgroud)
我定义了我的密钥库:
var iCloudStore = NSUbiquitousKeyValueStore.defaultStore()
Run Code Online (Sandbox Code Playgroud)
像这样设置我的价值:
iCloudStore.setValue(experience, forKey: "experience")
Run Code Online (Sandbox Code Playgroud)
为什么这不起作用?我是否必须定义该密钥才能工作?我真的不明白我得到的错误......
setValue:forKey:不是NSUbiquitousKeyValueStore.defaultStore()用于将数据保存到iCloud键值存储的方法.相反,它是来自NSKeyValueCoding协议的方法,用于更一般的键值编码与类型NSValue和NSNumber.您收到的错误是指您尝试访问iCloudStore对象本身而不是iCloud键值存储中的"体验"键.
NSUbiquitousKeyValueStore.defaultStore()保存键值对的可用方法是:
setArray:forKey:setBool:forKey:setData:forKey:setDictionary:forKey:setDouble:forKey:setLongLong:forKey:setObject:forKey:setString:forKey:选择最适合您类型的方法.
| 归档时间: |
|
| 查看次数: |
360 次 |
| 最近记录: |