2013-10-21 40 views
-1

我有這個簡單的代碼,我真的不能說發生了什麼:的NSDictionary未添加的NSMutableArray雖然數據是正確的

NSLog(@"Data: %@",[dataFromServer description]); 
    for (int i=0; i<[data count]; i++) { 
     NSLog(@"Processing data :%d",i); 
     NSDictionary *current=[data objectAtIndex:i]; 
     int category = [[current objectForKey:@"type"] intValue]; 
     NSLog(@"Category value:%d",category); 
     if (category == 1) { 
      NSLog(@"Hotel found %@",[current description]); 
      [hotelsFromServer addObject:current]; 
    } 
NSLog(@"Hotels. Total:%d Items:%@",[hotelsFromServer count],[hotelsFromServer description]); 

我從我的服務器(dataFromServer),這是正確打印取一個NSMutableArray 。每個對象都是一個NSDictionary。類別1表示該類型是酒店。我輸入if條款,酒店正在正確打印。

但外線,爲最終的NSLog,我得到這些:

Hotels. Total:0 Items:(null) 

這是爲什麼?當前項目是正確的。爲什麼它沒有添加到我的NSMutableArray中。

陣列的定義如下:

@implementation ClassName 
{ 
    NSMutableArray * dataFromServer; 
    NSMutableArray * hotelsFromServer; 
} 
+6

你'hotelsFromServer'是'nil' –

回答

0

確保你地初始化的NSMutableArray

self.hotelsFromServer = [[NSMutableArray裏的alloc] INIT];

在你的事業

數組是零我想和[零anyMessage]只是沒有做任何事情

相關問題