Using Nsuserdefaults with Xcode 8 and iOS 10

Using NSUserDefaults with Xcode 8 and iOS 10

NSUserDefaults has been renamed to UserDefaults. standardUserDefaults() has been renamed to standard().

let defaults = UserDefaults.standard

This now works.

Pre-release documentation link.

iOS 10, NSUserDefaults Does Not Work

I just had the same problem. There seems to be an issue with NSUserDefaults when first running the iOS8 or 9 simulator and then the iOS10 simulator.
Rebooting the mac solved the issue for me.

Error after xcode 8 update - NSUserDefaults

First of all if you want to pass around values inside your program just use local variables as @vikingosegundo stated. Declare local variables and use them.

Second, use NSUserDefault when you want to store variables like for example user-settings or preferences. Do also follow @Adils advice. Use them as follows:

Set value:

NSUserDefaults.standardUserDefaults().setObject("YOUR STRING", forKey: "key")

Get value:

NSUserDefaults.standardUserDefaults().stringForKey("key")

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.

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