2012-11-15 252 views
0

我有這個解析字符串的簡短方法。對象屬性未設置

NSMutableArray *aircraftMutableArray; 
- (void)parseAircraftRotations:(NSString*)inText 
    { 
    aircraftMutableArray = [NSMutableArray array]; 
    NSArray *inTextArray = [inText componentsSeparatedByString:@"\n"]; 

    for (NSString*line in inTextArray) 
    { 
     if ([line length] > 0) 
     { 
      if ([[line substringToIndex:1] isEqualToString:@"-"]) 
      { 
       aircraft = [[AirCraft alloc] init]; 
       [aircraft setRegistration:[line substringFromIndex:1]]; 
       [aircraftMutableArray addObject:aircraft]; 
       aircraft = nil; 
      } 
     } 
    } 

    for (AirCraft *ac in aircraftMutableArray) 
    { 
     NSLog(@"%@", [ac registration]); 
    } 
} 

我現在的問題是,NSLog輸出正確的行數,但[ac註冊]在每行上爲空。請幫助。

+0

什麼是你的[飛機註冊]方法是什麼樣子? –

回答

3

的問題是,飛機對象的屬性是這樣

@property (nonatomic, weak) NSString *registration; 

定義應該是強

@property (nonatomic, strong) NSString *registration;