Swift 3/iOS 10/Todayextension - Userdefaults Always Returns Nil

Swift 3 / iOS 10 / TodayExtension - UserDefaults always returns nil

I partially solved my problem.

I have completely remove Xcode and all the settings (caches files etc...),
then I have removed the "Team" part in the suite name.

Now I have like a warning in the Xcode console but I can retrieve my notes in my TodayExtension. Piouf !

I still have the problem for WatchKit Extension. I'm not sure but I think that I have read that UserDefaults even with App Groups are not shared with Apple Watch Extensions.

But Apple write in their documentation "Also, iOS automatically forwards a read-only copy of your iOS app’s preferences to Apple Watch. Your WatchKit extension can read those preferences using an NSUserDefaults object, but it cannot make changes directly to the defaults database."

So I don't know why I cannot retrieve my notes from my Apple Watch.

At least I have solved my first problem. If anybody has the same.

NSUserDefaults Multi Value is nil

You're querying for a dictionary value, but there's only a String stored in UserDefaults.

Use let stage = UserDefaults.standard.string(forKey: "stageSelection")

UserDefaults between iOS and WatchOS not working

Communication between watchKit and app using userDefaults has been removed.

It can be done using watchConnectivity framework

Save dictionary in userdefaults in swift 3 with xcode 8

This problem seems to be caused by having two versions of xcode/simulator installed.

What worked for me was uninstalling xcode 7 and just keeping xcode 8 beta on my system. Emptying trash, resetting the simulator and running. I also restarted my computer.

After following these steps the simulator is able to save to UserDefaults.



Related Topics



Leave a reply



Submit