nsuserdefaults

Get NSUserDefaults plist file from device

六月ゝ 毕业季﹏ 提交于 2019-12-04 08:36:58
When testing my app on the simulator, I like the ability to edit, or even trash the apps plist file (which contains the NSUserDefaults) from the iPhone Simulator folder. This proves useful when testing (e.g. your app stores a dictionary in there, but you change the model/keys that you use for this data, and therefore need to remove the dictionary stored). Is it possible to access this file on device (for your own app), without jailbreak? Thanks in advance Jano The file is in Library/Preferences . The file is a binary plist with name <iOS application target identifier>.plist (look for the

Change objects in NSUserDefaults without creating and re-setting copies

家住魔仙堡 提交于 2019-12-04 06:40:47
I've got dictionary stored in NSUserDefaults and I need to add/remove items in this dictionary. It bothers me that to do this I have to create mutable copy of entire dictionary, change one element and replace entire dictionary with new copy. copy = [[defaults objectForKey:@"foo"] mutableCopy]; [copy setObject:… forKey:@"bar"]; [defaults setObject:copy forKey:@"foo"]; and it involves even more copying and re-setting for objects deeper in the hierarchy. Is there a better way? I've tried to use [defaults setValue:… forKeyPath:@"foo.bar"] but that doesn't seem to work (object is not mutable). I

Check for first launch of my application

 ̄綄美尐妖づ 提交于 2019-12-04 06:37:54
How would I check if it is the first launch of of my application using NSUserDefaults and running some code for the first time my app opens? This should point you in the right direction: static NSString* const hasRunAppOnceKey = @"hasRunAppOnceKey"; NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; if ([defaults boolForKey:hasRunAppOnceKey] == NO) { // Some code you want to run on first use... [defaults setBool:YES forKey:hasRunAppOnceKey]; } The NSUserDefaults answer is the first thing that popped in my head, but upon reflection I will make another suggestion. A bit more work,

Storing NSMutableArray filled with custom objects in NSUserDefaults - crash

爷,独闯天下 提交于 2019-12-04 05:47:54
问题 EDIT: Here is a working version. I was able to retrieve my object within the NSMUtableArray after I saved and loaded it from the NSUserDefaults via NSCoding. I think it's important to mention, that you not only need to de-archive the array, but also all its content. As you can see, I had to not only store the NSData of my freeze object, but also the NSData of my array: // My class "Freeze" @interface Freeze : NSObject <NSCoding> // The NSCoding-protocoll is important!! { NSMutableString *name

When the app is deleted what happens to the values stored in NSUserDefaults?

夙愿已清 提交于 2019-12-04 05:23:28
I have a little question regarding NSUserDefaults . When the application is deleted, what happens to the values stored in the NSUserDefaults ? Do they get deleted as well? When I remove a app and reinstall it from the app store the previous NSUserDefaults values are loaded? When an app is deleted from the device all local data associated with the app will be deleted too. This includes NSUserDefaults . However any data stored at an online service won't. For example, iCloud. The app will just fetch the data again if requested to do so by the user / developer. Edit As per mAu's comment below -

UserDefaults Custom Object of Custom Objects

Deadly 提交于 2019-12-04 05:03:17
问题 Part of my settings I want to save with UserDefaults. I already found this solution here: Save custom objects into NSUserDefaults But I could not figure out how to save if I have custom objects in a custom object. My classes look like this: class ConfigLabelMainList: NSObject, NSCoding { var labelMiddleFirst: StatsIntervalModel var labelMiddleSecond: StatsIntervalModel var labelMiddleThird: StatsIntervalModel var labelRightFirst: StatsIntervalModel var labelRightSecond: StatsIntervalModel

Is data stored in NSUserDefaults persists through application updates and on application reinstallation (remove-install)?

独自空忆成欢 提交于 2019-12-04 04:56:58
It's important to my app, becuase I want to store app UDID there, and Apple recommends to create app specific UDID starting from iOS 5.0. User defaults are persisted through updates but are not persisted through deleting and re-installing the app. At present, the keychain is persisted through deleting and re-installing the app, but it's not documented to be one way or the other, so relying on this behavior may be risky. You could also write the value to the iCloud key/value store. That will be persisted across all installations of the app for that user and is kind of what it was designed for.

Settings bundle values returning nil

时光怂恿深爱的人放手 提交于 2019-12-04 03:46:55
I added a Settings bundle to my app and in Xcode it appears in the root of my project tree view. The Root.plist file looks like this: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>StringsTable</key> <string>Root</string> <key>PreferenceSpecifiers</key> <array> <dict> <key>Type</key> <string>PSGroupSpecifier</string> <key>Title</key> <string>Service</string> </dict> <dict> <key>Type</key> <string>PSTextFieldSpecifier</string> <key>Title</key> <string>Hostname</string

How can I store an array of custom objects (Goals)

雨燕双飞 提交于 2019-12-04 03:32:51
问题 How can I store an array of objects of type Goal which I have created in NSUserDefaults? (in swift) Here is the code: func saveGoalList ( newGoalList : [Goal] ){ let updatedGoalList = newGoalList; NSUserDefaults.standardUserDefaults().setObject(updatedGoalList, forKey: "GoalList") NSUserDefaults.standardUserDefaults().synchronize() } class GoalsViewController: MainPageContentViewController, UITableViewDelegate, UITableViewDataSource { @IBOutlet var tableView: GoalsTableView! var cell =

Saving array using NSUserDefaults crashes app

喜夏-厌秋 提交于 2019-12-04 02:50:39
问题 I feel as if I am doing things correctly, but I am getting an error at the end of my data conversion and retrieval. Please see the code below: class Task:NSObject, NSCoding { var name:String var notes:String var date:NSDate var taskCompleted:Bool init(name:String, notes:String,date:NSDate, taskCompleted:Bool){ self.name = name self.notes = notes self.date = date self.taskCompleted = taskCompleted } required init(coder decoder: NSCoder){ self.name = (decoder.decodeObjectForKey("name") as!