insert object in an NSMutableArray saved with NSUserDefaults

NSUserDefaults always returns immutable objects, even if the original object was mutable. It’s in the documentation for objectForKey: The returned object is immutable, even if the value you originally set was mutable. You will need to create a copy of the returned object before you modify it, using [NSMutableArray arrayWithArray:] Probably also best to use … Read more

Swift NSUserDefaults not saving Dictionary?

Update for Swift 2, Xcode 7: As @atxe noticed, NSUserDefaults dictionaries are now mapped as [String, AnyObject]. This is a consequence of the Objective-C “lightweight generics” which allow to declare the Objective-C method as – (NSDictionary<NSString *,id> *)dictionaryForKey:(NSString *)defaultName (Default objects must be property lists and in particular the dictionary keys can only be strings.) … Read more

NSUserDefaults or keychain is better to save username and password in iPhone app

NSUserDefaults is quite easy to use and stores one value per key only. But apparently, it is not a very secure method, as there is no encryption. But the Keychain is secure, though it is a bit hard to code. You can refer these link to use keychain access. http://log.scifihifi.com/post/55837387/simple-iphone-keychain-code you can also use this … Read more

How to save NSMutablearray in NSUserDefaults

Note: NSUserDefaults will always return an immutable version of the object you pass in. To store the information: // Get the standardUserDefaults object, store your UITableView data array against a key, synchronize the defaults NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; [userDefaults setObject:arrayOfImage forKey:@”tableViewDataImage”]; [userDefaults setObject:arrayOfText forKey:@”tableViewDataText”]; [userDefaults synchronize]; To retrieve the information: NSUserDefaults *userDefaults = [NSUserDefaults … Read more