Tim Specht
Tim Specht

Reputation: 3218

Xcode 6 flushing NSUserDefaults

my application stores some state information inside NSUserDefaults. When using Build & Run with the newest version of Xcode 6 (the GM), all the defaults are flushed upon install. In addition, values entered in my Settings.bundle are removed (which is another sign of the user defaults being flushed). Any suggestions on how to fix that?

Upvotes: 0

Views: 417

Answers (2)

Tim Specht
Tim Specht

Reputation: 3218

As it appears I was a little mislead. I checked for some files being present in the apps document directory on startup. If they were not, I removed stuff from the NSUserDefaults. Apple seems to have updated the Xcode Build&Run implementation leading to a new app file path (the identifier inside the path changes) each time Build&Run is executed. When simply restarting the app in a normal way without Build&Run (so as a normal user would do), everything is working fine and the path stays the same.

Upvotes: 1

Fahim Parkar
Fahim Parkar

Reputation: 31647

Use below. It will work now.

[[NSUserDefaults alloc] initWithSuiteName:@"group identifier"]; // this is introduced in iOS8
[[NSUserDefaults alloc] setValue:@"yes" forKey:@"test"];
[[NSUserDefaults alloc] synchronize];

If it still doesn't work, make Product>>Clean

Upvotes: 0

Related Questions