views:

48

answers:

1

Hey,

my question is a performance question. I need to split a huge NSString into coordinates. The string has this format:

@"coordx,coordy coordx,coordy coordx,coordy (...)"

My method to parse this is:

-(NSMutableArray*) parsePath:(NSString*) pathString
{

    // first split between the coordinates
    NSArray* path = [pathString componentsSeparatedByString:@" "];

    NSMutableArray* coords = [[NSMutableArray alloc] init];

    static NSString *seperator = @",";

    NSArray *coord;
    for(NSString *coordString in path)
    {
        coord = [coordString componentsSeparatedByString:seperator];

        Coordinate *c = [[Coordinate alloc]init];
        c.x = [[coord objectAtIndex:0] intValue];
        c.y = [[coord objectAtIndex:1] intValue];
        [coords addObject:c];
        [c release];
    }
    return coords;
}

So, is there any way to make this faster?

Thanks!

Sebastian