HOM with Objective C

Posted by Coxer on Stack Overflow See other posts from Stack Overflow or by Coxer
Published on 2010-04-12T14:22:20Z Indexed on 2010/04/13 1:32 UTC
Read the original article Hit count: 423

Filed under:

Hey, i am new to objective C, but i tried to use HOM in order to iterate over an NSArray and append a string to each element.

here is my code:

void print( NSArray *array ) {
    NSEnumerator *enumerator = [array objectEnumerator];
    id obj;

    while ( nil!=(obj = [enumerator nextObject]) ) {
        printf( "%s\n", [[obj description] cString] );
    }
}


int main( int argc, const char *argv[] ) {
 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

 NSArray *names = [[NSArray alloc] init];
 NSArray *names_concat = [[NSArray alloc] init];
 names = [NSArray arrayWithObjects:@"John",@"Mary",@"Bob",nil];
 names_concat = [[names collect] stringByAppendingString: @" Doe"];

 print(names_concat);
 [pool release];
}

What is wrong with this code?

My compiler (gcc) says NSArray may not respond to "-collect"

© Stack Overflow or respective owner

Related posts about objective-c