2017-08-17 4 views
0

iCloudからkeyValueペアを使用してintを取得しようとしています。誰かが私にこのエラーでクラッシュする理由を説明することができます:iCloud keyValueゲームをクラッシュする

'[<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") 
    } 

答えて

1

値(forKey :)は、オブジェクトのインスタンス変数に動的にアクセスするためのものです。 I.キーバリューコーディング。

"current"という名前のインスタンス変数はありません。ストアに格納されている値にアクセスするには、オブジェクト(forKey :)を使用してドキュメントを実行する必要があります。

関連する問題