NSUserDefaults

Dok-tips for Foundation class NSUserDefaults

Characteristics

Its a singleton instance fetched through its class method standardUserDefaults for storing the defaults of an application in persistent memory and its data must conform to the limitations of a property list

Mutable only in the sense that you can overwrite it

Everytime you pull out the data from NSUserDefaults, it is Immutable - even if you put mutable data into it

Must remember to call its synchronize function after each batch of changes

[[NSUserDefaults standardUserDefaults] synchronize];

Example methods

- (void)setDouble:(double)aDouble forKey:(NSString *)key;
- (NSInteger)integerForKey:(NSString *)key;
- (void)setObject:(id)obj forKey:(NSString *)key; // obj must be a Property List
- (NSArray *)arrayForKey:(NSString *)key; // will return nil if value for key is not NSArray
NSMutableDictionary * mutableCopyOfUserDefaults = [[[NSUserDefaults standardUserDefaults] dictionaryForKey:SOMEKEYOFMINE] mutableCopy];

History notes


List of all foundation classes