0 Replies
      Latest reply on May 18, 2020 4:22 AM by Desbrina
      Desbrina Level 1 Level 1 (0 points)

        I'm trying to move from NSUserDefaults so that the values sync across devices. The value I'm trying to sync is a single bool, to identify if an initial data import has been done.

        I'm using the following code

         

        var keyValStore = NSUbiquitousKeyValueStore()
        
        keyValStore.synchronize()
        let firstRun: Bool = keyValStore.bool(forKey: "firstRun")
        NSLog("First Run: \(firstRun)")
        if(!firstRun) {
          keyValStore.set(true, forKey: "firstRun")
          keyValStore.synchronize()
        }

         

        If I run the app on my iPhone, it works as expected, the import only works once. If I then run the app on my iPad, it does that import again when it shouldn't, the log shows

        First Run: false