Maxhirez
Maxhirez

Reputation: 99

NSTimer Syntax in Xcode 3

I'm using an old 12" Powerbook for the brains of a mobile robot platform and I'm having trouble getting the NSTimer to compile in XCode 3.2.3. Creating a standard tool in C, Using:

[NSTimer scheduledTimerWithTimeInterval:2.0
target:self
selector:@selector(targetMethod:)
userInfo:nil
repeats:NO];

When I build I get a "Syntax error before [ token." or "Syntax Error before { token." depending on where the NSTimer call shows up.

Any pointers?

Upvotes: 0

Views: 215

Answers (2)

jscs
jscs

Reputation: 64002

Creating a standard tool in C [emphasis mine]

This is Objective-C syntax, and NSTimer is an Objective-C object. The C compiler doesn't know what to do with it. You should start with the "Command Line Tool" Template, and specify "Foundation" in the pop-up menu. Foundation is Apple's base Objective-C framework. It includes NSTimer and also importantly, the build settings for your project will include compiling as Objective-C. enter image description here

Upvotes: 1

logancautrell
logancautrell

Reputation: 8772

Make sure you are linking against Foundation in your project, though I would expect missing symbol error in that case.

Your syntax for this line of code is correct, so it is not related directly to this line.

Upvotes: 0

Related Questions