retain array into NSDefault?
HI all,
can we开发者_JAVA技巧 retain an array in NSDefualt?
regards shishir
If you mean store an array, then the answer is yes. You just use the setObject:forKey:
method to store it. So:
NSArray* myArray = [NSArray arrayWithObjects:@"One", @"Two", @"Three", nil];
[[NSUserDefaults standardUserDefaults] setObject:myArray forKey:@"myArrayKey"];
// much later...
NSArray* thatArray = [[NSUserDefaults standardUserDefaults] arrayForKey:@"myArrayKey];
NSLog(@"thatArray second object: %@", [thatArray objectAtIndex:1]);
// prints "thatArray second object: two"
I guess that you are asking for:
You have an array, you put it into NSUserDefaults, then later, you want to retain that array, is it right?
NSUserDefaults will not retain your array when you put it into. It just save and get data through serialization to a database So, if you currently hold your array, you don't need to retain it any more.
精彩评论