私は過去1時間これを解決しようとしてきましたが、まだ運がありませんでした
次のクラスのオブジェクトを保持する NSMutableArray インスタンス変数があります:配列は、私がそれを移入するメソッドで正常に移入されますが、他のすべてのメソッド/クラスでは空として表示されます
.h ファイル...
#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 ファイル
@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<<<<<< }
}