Thanks for you time and reading this. What I'm trying to do is figure out why this NSLog is telling me the array is always null, no matter what. I'm thinking that the problem is that I'm initiating the MutableArray wrong. Could you perhaps take a look and decide whether or not I did it right, and if at all possible give me a way to pass the array into the MutableArray?
Thanks!
//Get Defaults
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSArray *favoriteArray = [[defaults objectForKey:@"favorites"] copy];
//Declares Mutable Array
self.favorites = [[NSMutableArray alloc] initWithObjects:favoriteArray, nil];
NSLog(@"array: %@", favorites);
UPDATE: I figured it out. It turns out you have to declare it with initWithArray rather than trying to add it as an object
Solution:
- (void)viewDidLoad {
//Get Defaults
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSArray *favoriteArray = [[defaults objectForKey:@"favorites"] copy];
//Declares Mutable Array
self.favorites = [[NSMutableArray alloc] initWithArray:favoriteArray];
[super viewDidLoad];
}
favoriteArray
, notfavorites
. – ThomasW Mar 5 '12 at 4:04[[defaults objectForKey:@"favorites"] copy]
is your problem line i think – Aram Kocharyan Mar 5 '12 at 4:21