nsuserdefaults

UIPickerView won't display the data loaded from NSUserDefaults - App is crashing while loading data

这一生的挚爱 提交于 2020-01-05 13:08:57
问题 I made a first try to use NSUserDefaults in an App with UIPickerViews. But the App is crashing while testing / the data isn't displayed in the PickerView. I still try to fix it myself but some help would be great. ViewController3: Where the user should save data to the NSUserDefault. Therefore there is an textField to write down something and a "Savebutton" class ViewController3: UIViewController, UITextFieldDelegate { @IBOutlet weak var textField: UITextField! ... @IBAction func

UIPickerView won't display the data loaded from NSUserDefaults - App is crashing while loading data

ⅰ亾dé卋堺 提交于 2020-01-05 13:08:12
问题 I made a first try to use NSUserDefaults in an App with UIPickerViews. But the App is crashing while testing / the data isn't displayed in the PickerView. I still try to fix it myself but some help would be great. ViewController3: Where the user should save data to the NSUserDefault. Therefore there is an textField to write down something and a "Savebutton" class ViewController3: UIViewController, UITextFieldDelegate { @IBOutlet weak var textField: UITextField! ... @IBAction func

What is the difference between object(forKey:) and value(forKey:) in UserDefaults?

蓝咒 提交于 2020-01-04 04:56:28
问题 I've set some user defaults using let userDefaults = UserDefaults.standard , and when I'm retrieving them, I can use any of these: jobTextField.text = userDefaults.object(forKey: "job") as? String OR I can use jobTextField.text = userDefaults.value(forKey: "job") as? String in what case this will has a difference? It'd be great to know when I can NOT use one of them. Thanks a lot :) 回答1: value(forKey:) is from key-value coding, and not a direct method of UserDefaults . Never use value(forKey:

Preventing NSUserDefaults from iCloud Backup

青春壹個敷衍的年華 提交于 2020-01-04 01:48:09
问题 There are three ways to write persistently to the device in iOS that I'm aware of: NSUserDefaults Custom Objects - Archived and Written to a PATH in NSDocuments SQLite Apple provide a mechanism to prevent iCloud backups with #2 i.e. - (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL I use NSUserDefaults to store three images but to adhere to iOS Data Storage Guidelines - How do I prevent Backups with iCloud with NSUserDefaults? This question has been asked several times on SO but there is

Difference between UserDefaults() and UserDefaults.standard

久未见 提交于 2020-01-03 21:09:42
问题 Is there a difference between UserDefaults() and UserDefaults.standard in Swift 3.0? 回答1: UserDefaults - Gives you a new object , each object is allocated a different memory and deallocated when object scope is finished. UserDefaults.standard - Gives you the singleton object by using the class method standard the object received by this method is allocated single memory throughout the application. And the usage of them if you´re interesedted in that: // Set UserDefaults.standard.set("YOUR

NSUserDefaults standardUserDefaults not working with extension

坚强是说给别人听的谎言 提交于 2020-01-03 12:59:19
问题 I added App Groups to my app ID in the developer portal and am using that App ID in my provisioning profile. My Product Identifier in Xcode is set to that app ID. In my app delegate I call this from didFinishLaunchingWithOptions NSUserDefaults.standardUserDefaults().setObject("hey", forKey: "TEST") NSUserDefaults.standardUserDefaults().synchronize() In my keyboard app extension I call this: if let test = NSUserDefaults.standardUserDefaults().objectForKey("TEST") as? String { println(test) }

how to use NSDictionary in NSUserDefault?

余生长醉 提交于 2020-01-03 05:02:54
问题 I want to know how can I use NSDictionary in NSUserDefault ? I have to store name, points and time of user into the NSDictionary and dictionary into the user default. 回答1: NSDictionary *dict = [[NSDictionary alloc] init]; [[NSUserDefaults standardUserDefaults] setObject:dict forKey:@"dict"]; [[NSUserDefaults standardUserDefaults] synchronize]; At the time of retrieval of data, dict = [[NSUserDefaults standardUserDefaults] objectForKey:@"dict"]; 回答2: NSUserDefaults *defaults = [NSUserDefaults

Did Apple change NSUserDefaults sharing from iOS app to watchOS app

旧时模样 提交于 2020-01-03 04:44:08
问题 I want to ask about how to use NSUserDefaults on watchOS app. Is its data different from iOS app's NSUserDefaults 's data? There are a lot of stackoverflow questions about this topic and all of them have same answers. That said, for example Watch apps that shared data with their iOS apps using a shared group container must be redesigned to handle data differently. In watchOS 2, each process must manage its own copy of any shared data in the local container directory. For data that is actually

Objective-c singleton object does not working as expected

血红的双手。 提交于 2020-01-03 04:32:26
问题 I have a problem. There is class to store game progress: struct GameData { PackData & packDataById(LEVEL_PACK packId); int gameVersion; AudioData audio; PackData sunrise; PackData monochrome; PackData nature; }; //singleton @interface GameDataObject : NSObject <NSCoding> { GameData data_; } +(GameDataObject*) sharedObject; -(id) initForFirstLaunch; -(GameData*) data; -(void) save; @end and implementation: @implementation GameDataObject static GameDataObject *_sharedDataObject = nil; +

How to deal with non-optional values in NSUserDefaults in Swift

喜欢而已 提交于 2020-01-03 03:08:10
问题 To get a value from NSUserDefaults I would do something like this: let userDefaults = NSUserDefaults.standardUserDefaults() if let value = userDefaults.objectForKey(key) { print(value) } However, these methods do not return optionals: boolForKey (defaults to false if not set) integerForKey (defaults to 0 if not set) floatForKey (defaults to 0.0 if not set) doubleForKey (defaults to 0.0 if not set) In my app I want to used the saved value of an integer if it has been previously set. And if it