Cub71
Cub71

Reputation: 323

Objects property not set

I have this short method that is parsing a string.

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]);
    }
}

My problem now is that the NSLog prints out the correct number of lines, but the [ac registration] is null on each line. Pls help.

Upvotes: 0

Views: 29

Answers (1)

Cub71
Cub71

Reputation: 323

The problem was that the property of the Aircraft object was defined like this

@property (nonatomic, weak) NSString *registration;

Should be strong

@property (nonatomic, strong) NSString *registration;

Upvotes: 3

Related Questions