i have this array called favorites referenced in my app delegate.
When i access it in the view controller i use this code
MultiViewAppDelegate *app = (MultiViewAppDelegate *)[[UIApplication sharedApplication] delegate];
[app.favoritesArray addObject:@"one"];
And in the table thats supposed to display this information im trying to ask if the array contains a certain element and if it does to display that item using this code.
NSLog (@"2");
favoritesArray = [[NSMutableArray alloc]init];
didContain = [[NSMutableArray alloc]init];
NSLog (@"3");
if ([favoritesArray containsObject:@"one"])
{[didContain addObject:@"one"];
NSLog (@"4"); }
however the code isnt running after nslog 3…
can someone inform me why?
Firstly,
The above line will reset your favoritesArray. It will also leak the old one.
Here, you’re simply asking an empty array if it contains something, which it obviously doesn’t.
Which is why none of the above ever happens.
Instead of resetting it, make sure it’s set instead.
You probably don’t need
favoritesArray != nil, but I put it in because you might have put your alloc-init stuff in because you sometimes get a nil value here. Unlikely though.That should probably do it.