NSMutableArray not retaining values outside of method
Ive been trying to solve this for the past one hour, but still had no luck
I have an NSMutableArray instance variable which holds objects in the
following class:The array successfully gets populated in the method i
populate it in, but it shows up as empty in all other methods/classes
.h file...
import "RedditPostItem.h"
@interface RedditRepository : NSObject
@property (nonatomic, strong) NSMutableArray redditPosts; //<<* this is
the problem array
@property (nonatomic, strong,readwrite) NSDictionary *allJSONData;
@property (nonatomic, strong,readwrite) NSMutableData *incomingData;
(void)getPosts;
(void)printAllTitles;
@end
.m file
@implementation RedditRepository . . @synthesize redditPosts=_redditPosts;
. .
(void)connectionDidFinishLoading:(NSURLConnection *)connection {
self.redditPosts = [[NSMutableArray alloc] initWithCapacity:20];
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
//parse json data
_allJSONData = [NSJSONSerialization JSONObjectWithData:_incomingData
options:0 error:nil];
NSDictionary *dataDictionary = [_allJSONData objectForKey:@"data"];
NSArray *arrayOfChildren = [dataDictionary objectForKey:@"children"];
for (NSDictionary *diction in arrayOfChildren) {
NSDictionary *childrenData = [diction objectForKey:@"data"];
RedditPostItem *postItem = [[RedditPostItem
alloc]initWithAPIResponse:childrenData];
//***************** add to array..... [self.redditPosts addObject:postItem];
}
//* if i iterate through 'self.redditPosts' i can see everything uptill
this point and the array successfully gets populated//
}
//*** if I execute any operation from any other method in this class or
any other class...the array shows up as empty!!*//
(void)printAllTitles{ if(self.redditPosts == nil) { NSLog(@"array is
empty....."); ///always shows up as empty for some reason<<<<<< } }
No comments:
Post a Comment