I have a function on a background thread that looks like this:
NSMutableArray *descriptions = [[NSMutableArray alloc] init];
NSString *description = [flickrFetcher descriptionForPhotoID:[[photos objectAtIndex:i] objectForKey:@"id"]];
if ([description length] == 0) {
description = @"No description available.";
}
[descriptions addObject:description];
NSLOg(@"descriptions:%@.", descriptions);
[target performSelectorOnMainThread:action withObject:descriptions];
In action:
NSLog(@"description now is:%@.", descriptions");
Logs:
Descriptions:2011-12-22 15:13:29.265 Paparazzi[3683:11903] (
"No description available.",
"No description available.",
"No description available.",
"No description available.",
"No description available.",
"No description available.",
"No description available.",
"No description available.",
"This is a photo of just the eyes of an image I created by editing Apple's snow leopard image. I call the whole image \"Thermal Leopard\"."
).
descriptions:(null).
In that function, descriptions (the array) always ends up as nil. Why is this happening?
EDIT 1:
The second time I call this function, the array is not nil and every thing works as expected. It is just the first time this code is called. Also, it is only nil in the main thread action method, not in the code shown above.
EDIT 2:
Is this a bug? Should I submit it to Apple?
I think this might not be my fault, if I could get suggestions on wether this is a bug or not that would be great.
I figured out the problem. Somewhere in the action method, I found that I was setting description to nil. Thank you all soooo much for your help. I am upvoting all of your answers and comments to thank you.