Andrey Chernukha Andrey Chernukha - 1 year ago 95
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?

Answer Source

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"];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download