Search code examples
objective-carrayscocoaosx-snow-leopardobjective-c-literals

Rewrite literal NSArray to compile on gcc for OS X 10.6


I got a suggestion here on SO to write this line:

NSArray *files = @[url];

However my Xcode/gcc is outdated as I'm still using OSX 10.6.

How do I rewrite this line so that it will compile?


Solution

  • If you need to use the old style Objective-C syntax you would write:

    NSArray *files = [NSArray arrayWithObjects:url, nil];
    

    or just:

    NSArray *files = [NSArray arrayWithObject:url];
    

    Look at the documentation for NSArray.