[Solved] All NSUserDefaults, all in tableview

You can set an array to userDefaults, the implementation is very simple. – (void)viewDidLoad { [super viewDidLoad]; [self addTextToUserDefaults:@”hello”]; [self addTextToUserDefaults:@”how are you?”]; [self addTextToUserDefaults:@”hi”]; for (NSString *text in [self textsInUserDefaults]) { NSLog(@”%@”, text); } } – (void)addTextToUserDefaults:(NSString *)aText { NSMutableArray *texts = [[[NSUserDefaults standardUserDefaults] objectForKey:@”textArray”] mutableCopy]; if (!texts) { texts = [NSMutableArray new]; } … Read more

[Solved] How to store array of values in NSUserDefaults in swift

let array = [1, 2, 9, 3, 22] UserDefaults.standard.set(array, forKey: “studentIDs”) //get id’s array from user defaults let studentIdsArray = UserDefaults.standard.array(forKey: “studentIDs”) There are plenty of questions/solutions, here is one: how to save and read array of array in NSUserdefaults in swift? But as another user said, please take a look at the official documentation: … Read more

[Solved] How to save User Name and Password in NSUserDefault?

For Saving Username and Password I will personally suggest to use Keychain as they are more safer than NSUserDefault in terms of security since Keychain stores data in encrypted form while NSUserDefault stores as plain text. If you still want to use NSUserDefault Here’s the way FOR SAVING NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults]; // saving … Read more

[Solved] What am I doing wrong with this NSMutableArray of structs in NSUserDefaults? “attempt to insert non-property list object”

From the NSUserDefaults Class Reference: A default object must be a property list, that is, an instance of (or for collections a combination of instances of): NSData, NSString, NSNumber, NSDate, NSArray, or NSDictionary. If you want to store any other type of object, you should typically archive it to create an instance of NSData. The … Read more

[Solved] Save an Object into User Defaults [duplicate]

The UserDefaults class provides convenience methods for accessing common types such as floats, doubles, integers, Boolean values, and URLs. A default object must be a property list—that is, an instance of (or for collections, a combination of instances of) NSData, NSString, NSNumber, NSDate, NSArray, or NSDictionary. If you want to store any other type of … Read more

[Solved] NSUserDefaults for high score is not working on iOS 8 Simulator?

Let’s step through your code. First, you overwrite whatever the high score was with 0: //To save highest score let highscore = 0 let userDefaults = NSUserDefaults.standardUserDefaults() NSUserDefaults.standardUserDefaults().setObject(highscore, forKey: “highscore”) NSUserDefaults.standardUserDefaults().synchronize() Then, you’re checking if “highscore” is in the defaults: if let highscore: AnyObject = userDefaults.valueForKey(“highscore”) { A few notes: This will always be true … Read more