Question

I get 'expected expression' error for below code in Xcode5. I created a command line tool project using Xcode5. Any idea of this error? My build setting does have ARC enabled.

    #include <stdio.h>

int main(int argc, const char * argv[])
{

   @autoreleasepool {

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

        [items addObject:@"One"];
        [items addObject:@"Two"];
        [items addObject:@"Three"];

        [items insertObject:@"Zero" atIndex:0];

        items = nil;
    }

    return 0;
}
Was it helpful?

Solution

First eliminate the extra "@".

Import Foundation:

#import <Foundation/Foundation.h>

Next:

items = null;

replaced the objects added to items, is that what you want?
Also null is not an Objective-C construct, rather it is an undeclared identifier. Perhaps it should be:

items = nil;

The following compiles error free:

#import <Foundation/Foundation.h>
int main(int argc, char *argv[]) {
    @autoreleasepool {
        NSMutableArray *items = [[NSMutableArray alloc] init];
        [items addObject:@"One"];
        [items addObject:@"Two"];
        [items addObject:@"Three"];
        [items insertObject:@"Zero" atIndex:0];
        items = nil;
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top