OK, so I can see that the notification is being fired and the value is being changed but the notification appears to be fired after the initial import is done.
From the notification
Code Block NSLog("First Run: \(String(describing: notification.userInfo))") |
First Run: Optional([AnyHashable("NSUbiquitousKeyValueStoreChangedKeysKey"): <__NSArrayM 0x60000391c450>( firstRun, timeGrouping, imageThumbSize, dbVersion ) , AnyHashable("NSUbiquitousKeyValueStoreChangeReasonKey"): 1])
Launching the application
Code Block func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { |
appData.moc = persistentContainer.viewContext |
NotificationCenter.default.addObserver(self, selector: #selector(onUbiquitousKeyValueStoreDidChangeExternally(notification:)), name: NSUbiquitousKeyValueStore.didChangeExternallyNotification, object: NSUbiquitousKeyValueStore.default) |
performUpdates() |
return true |
} |
and the performUpdates function
Code Block func performUpdates() { |
let firstRunPref: Bool = prefs.bool(forKey: "firstRun") |
let firstRun: Bool = keyValStore.bool(forKey: "firstRun") |
if(!firstRun) { |
// Check for old prefs, if existing, there is already data in the db |
if(!firstRunPref) { |
// No previous data |
keyValStore.set(true, forKey: "firstRun") |
NSLog("First Run: Yes inital keyval, no prefs, initial import") |
} else { |
// Previous data exists |
keyValStore.set(true, forKey: "firstRun") |
NSLog("First Run: Yes inital keyval, previous prefs, convert") |
} |
} else { |
updates(useKeyVal: true) |
NSLog("First Run: No, update") |
} |
} |