对象属性未设置

时间:2012-11-15 21:24:34

标签: objective-c arrays macos

我有这个解析字符串的简短方法。

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 registration]为空。请帮助。

1 个答案:

答案 0 :(得分:3)

问题在于飞机物体的属性是这样定义的

@property (nonatomic, weak) NSString *registration;

应该是强大的

@property (nonatomic, strong) NSString *registration;