我有这个解析字符串的简短方法。
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]为空。请帮助。
答案 0 :(得分:3)
问题在于飞机物体的属性是这样定义的
@property (nonatomic, weak) NSString *registration;
应该是强大的
@property (nonatomic, strong) NSString *registration;