我有这个解析字符串的简短方法。
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] 在每一行上都是空的。请帮忙。