Here I am parsing my JSON Data in a GCD Queue . Here i am using a class method to get the values. In my GCD queue i am allocating and releasing some arrays . Is this a right way to do in a GCD queue or i have to use the __block specifier. Want to clear my confusion
+ (void)startProcessingFeeds:(NSData *)fetchedData{
dispatch_queue_t concurrentQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(concurrentQueue, ^(void) {
NSMutableArray *idArrayTemp = [[NSMutableArray alloc] init];
NSMutableArray *titleArrayTemp = [[NSMutableArray alloc] init];
NSMutableArray *filesArray = [[NSMutableArray alloc] init];
MBFeeds *feeds = [MBFeeds getFeeds];
NSString *response = [[[NSString alloc] initWithData:fetchedData encoding:NSASCIIStringEncoding] autorelease] ;
NSMutableDictionary *newsDic = [response JSONValue];
NSMutableDictionary *tempNested = [newsDic valueForKey:@"data"];
/* here i am taking the values from dictionary and storing that to a array in my Singleton class */
[idArrayTemp release];
[titleArrayTemp release];
[filesArray release];
});
}
If I understand you correctly you are reading data and then storing it in a singleton so you can access it somewhere else. As long as the singleton is ensuring the data is retained (by using retained properties for example) then there should be no problem with your code.
__block is only needed when you want to create a variable out side of a block and have it manipulated inside a block. An example is when using a block to process array data.