gpt4 book ai didi

swift - iCloud keyValue 使我的游戏崩溃

转载 作者:行者123 更新时间:2023-11-28 15:22:38 27 4
gpt4 key购买 nike

尝试使用键值对从 iCloud 检索一个整数。有人可以向我解释为什么这会因错误而崩溃:

 '[<NSUbiquitousKeyValueStore 0x170287e40> valueForUndefinedKey:]: this class is not key value coding-compliant for the key current.'

它在我之前的项目中运行良好。

 var iCloudKeyStore: NSUbiquitousKeyValueStore = NSUbiquitousKeyValueStore()

func loadSavedData() {

if let cloudCurrent = iCloudKeyStore.value(forKey: "current") as! Int? { /* <-------- Crashes on this line */
print("Current Level Found From iCloud: \(cloudCurrent)")
currentLevel = cloudCurrent
}else{
print("No Current Level Found")
}

if let cloudAchieved = iCloudKeyStore.value(forKey: "achieved") as! Int? {
print("Current Level Found From iCloud: \(cloudAchieved)")
levelAchieved = cloudAchieved
}else{
print("No Achieved Level Found")
}

最佳答案

value(forKey:) 用于动态访问对象的实例变量。 IE。键值编码。

该对象上没有名为“current”的实例变量。您想要访问存储在商店中的值,根据文档,应该使用 object(forKey:) 来完成。

关于swift - iCloud keyValue 使我的游戏崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45724914/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com