Objective c 如何修复NSTimer中“将'void(void)'发送到'SEL _Nonnull'类型参数的不兼容指针类型”
在Objective C中,我试图创建在构造函数中的NSTimer选择器上调用的方法。但是,我遇到了这个错误,导致我的应用程序在构建时失败: 不兼容的指针类型将“void void”发送到“SEL\u Nonnull”类型的参数Objective c 如何修复NSTimer中“将'void(void)'发送到'SEL _Nonnull'类型参数的不兼容指针类型”,objective-c,nstimer,Objective C,Nstimer,在Objective C中,我试图创建在构造函数中的NSTimer选择器上调用的方法。但是,我遇到了这个错误,导致我的应用程序在构建时失败: 不兼容的指针类型将“void void”发送到“SEL\u Nonnull”类型的参数 @implementation Employee void timerMethod(void); - (id)init { self = [super init]; if (self) { _person = [[Person alloc
@implementation Employee
void timerMethod(void);
- (id)init {
self = [super init];
if (self) {
_person = [[Person alloc] init];
_timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:(timerMethod) userInfo:nil repeats:YES];
}
return self;
}
int counter = 0;
int timeUp = 10;
- (void) timerMethod {
counter += 1;
while (counter != timeUp) {
NSLog(@"A new person has been added");
[_timer invalidate];
counter ++;
}
}
您必须创建一个@selector
您必须创建一个@selector
_timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timerMethod) userInfo:nil repeats:YES];