0

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?

logancautrell
  • 8,762
  • 3
  • 39
  • 50
Maxhirez
  • 99
  • 7

2 Answers2

1

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

jscs
  • 63,694
  • 13
  • 151
  • 195
0

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.

logancautrell
  • 8,762
  • 3
  • 39
  • 50