nsuserdefaults

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

纵然是瞬间 提交于 2019-12-21 11:14:55
问题 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? 回答1: 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

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

别等时光非礼了梦想. 提交于 2019-12-21 10:57:05
问题 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. 回答1: 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

iPhone: Not able to store NSMutableDictionary to NSUserDefaults

孤街醉人 提交于 2019-12-21 05:56:40
问题 I am trying to implemen "Add to Favorites" functionality using NSMutableDictionary as I have to add multiple key-values. The following addToFavourites method always display Count=0 even after adding object to dictionary. I read this and getting nsdefaults into mutabledictionary(instead of mutable array) and setting resulted dictionary back to nsdefaults but not sure what's the problem. Any help would be really appreciated. Thank you. Edited: From this I came to know that I have to move data

What is the best way to save an NSMutableArray to NSUserDefaults?

微笑、不失礼 提交于 2019-12-21 05:01:05
问题 I have a custom object called Occasion defined as follows: #import <Foundation/Foundation.h> @interface Occasion : NSObject { NSString *_title; NSDate *_date; NSString *_imagePath; } @property (nonatomic, retain) NSString *title; @property (nonatomic, retain) NSDate *date; @property (nonatomic, retain) NSString *imagePath; Now I have an NSMutableArray of Occasions which I want to save to NSUserDefaults. I know it's not possible in a straight forward fashion so I'm wondering which is the

Is it safe to rely on NSUbiquitousKeyValueStore for storing essential data?

天大地大妈咪最大 提交于 2019-12-21 04:25:20
问题 I learned that NSUbiquitousKeyValueStore is always available, also when no iCloud account is set up. This makes me believe I can safely store essential data in it, without keeping a copy in NSUserDefaults . However, in their documentation, Apple says the following: Avoid using this class for data that is essential to your app’s behavior when offline; instead, store such data directly into the local user defaults database. Do I overlook issues that might arise when not using NSUserDefaults (or

How to save data with NSUserDefaults using data from NSMutableArray

倖福魔咒の 提交于 2019-12-21 02:51:44
问题 My NSMutableArray is declared in my .h file like this @property (strong, nonatomic) NSMutableArray * numbers; How do I use the NSMutableArray to save the data that is inputed to save to NSUserDefaults All help is appreciated Thanks in advance code in .h file @property (retain, nonatomic) IBOutlet UITableView *myTableView; @property (strong, nonatomic) NSMutableArray * numbers; code in .m @synthesize myTableView, numbers; -(void) viewDidLoad { NSUserDefaults *defaults=[NSUserDefaults

How to remove all UserDefaults data ? - Swift [duplicate]

梦想与她 提交于 2019-12-20 11:03:24
问题 This question already has answers here : Delete all keys from a NSUserDefaults dictionary iOS (15 answers) Closed 2 years ago . I have this code to remove all UserDefaults data from the app: let domain = Bundle.main.bundleIdentifier! UserDefaults.standard.removePersistentDomain(forName: domain) print(Array(UserDefaults.standard.dictionaryRepresentation().keys).count) But I got 10 from the print line. Shouldn't it be 0 ? 回答1: The problem is you are printing the UserDefaults contents, right

Save variable after my app closes (swift)

孤街醉人 提交于 2019-12-20 09:45:53
问题 I'm trying to save a variable in Xcode so that it saves even after the app has closed, how ever when I access it I do it from a several different classes and files, and I change the value of the variable when I access it. Therefore similar threads do not completely apply, the value to be stored is a string and here is the code I have up until now: var defaults: NSUserDefaults = NSUserDefaults.standardUserDefaults() defaults.setObject(Token, forKey: "") as! String I believe this is the correct

How to use NSUserDefaults to store an array of dictionaries

会有一股神秘感。 提交于 2019-12-20 06:03:52
问题 Trying to store an array of dictionaries with NSUserDefaults . var theTasks: [[String:Any]] = [["num":1,"title":"example","colour":"red"]] let defaults = NSUserDefaults.standardUserDefaults() defaults.setObject(theTasks, forKey: "myTasks") defaults.synchronize() let selected = theTasks[1] Gives error: Cannot convert value of type '[[String:Any]]' to expected argument of type 'AnyObject?' 回答1: Swift 3.x In Swift 3 it has changed so now it needs to be saved as [Any] Any Array and use

Best Practice using an Array of Strings with NSUserDefault

孤者浪人 提交于 2019-12-20 03:52:26
问题 I'm having a bit trouble saving an array of strings to userDefaults. I have an Array of strings declaired in a class, with a property observer ment to sync to userDefaults. Furthermore, I want the array to be limited to a maximum of 5 Strings. let userDefaults = NSUserDefaults.standardUserDefaults() var suggestions: [String]! { didSet { var arrayEnd = suggestions.count if arrayEnd >= 5 { arrayEnd = 4 } let newArray = Array(suggestions[0...arrayEnd]) userDefaults.setObject(newArray, forKey: