Am having some trouble with a simple callback; am getting an ‘expected method body’ error even though I can’t find anything wrong. Have commented the error messages.
Logger.h
#import <Foundation/Foundation.h>
@interface Logger : NSObject
- (void)sayOuch:NSTimer *)t; // Expected ';' after method prototype
@end
Logger.m
#import "Logger.h"
@implementation Logger
- (void)sayOuch:NSTimer *)t // expected method body
{
NSLog(@"Ouch!");
}
@end
main.m
#import <Foundation/Foundation.h>
#import "Logger.h"
int main (int argc, const char * argv[])
{
@autoreleasepool {
Logger *logger = [[Logger alloc]init];
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:2.0
target:logger
selector:@selector(sayOuch:)
userInfo:nil
repeats:YES];
[[NSRunLoop currentRunLoop]run];
}
return 0;
}
You have
But you should have
You missed the opening parenthesis for
NSTimer *