Andrey Chernukha Andrey Chernukha - 1 month ago 9
Objective-C Question

what does [[NSUserDefaults standardUserDefaults ] objectForKey] return?

if i'm doing this

NSArray * myArray = [[NSArray alloc] init];
myArray = [[NSUserdefaults standardUserDefaults] objectForKey:@"array"];
[myArray release];

am i destroying value stored in NSUserDefaults for key @"array"? Is it still extractable or not already? Does [[NSUserdefaults standardUserDefaults] objectForKey:@"array"]; return pointer or value?


Your call to objectForKey is returning an autoreleased array.

Don't do the alloc/init or release thing around that. You'd be leaking and most likely crashing.

Just do:

NSArray * myArray = [[NSUserDefaults standardUserDefaults] objectForKey: @"array"];