Sucrenoir
Sucrenoir

Reputation: 3034

How does work scheduleOnce with a selector and params?

Xcode is expecting a ')' just before the YES

[_creep scheduleOnce:@selector(removeFromParentAndCleanup:YES) delay:2.0f];

Sorry if it seems basic stuff... I just started ObjectiveC.

Upvotes: 0

Views: 390

Answers (1)

CodaFi
CodaFi

Reputation: 43330

Because the Cocos API limits you to one selector with 1 argument (ccTime), write your own method that passes the given arguments to the proper function:

-(void)doneWithSomething {
    [self scheduleOnce:@selector(removeAndCleanup:) delay:2.0f];
}

-(void)removeAndCleanup:(ccTime)delta {
    [ _creep removeFromParentAndCleanup:YES];
}

You cannot pass arguments in the @selector() directive because it directly correlates to an entry in either a vTable (for common methods) or an entry in the ObjC sel cache, so the compiler thinks you're trying to invoke an impossibly named method called -removeFromParentAndCleanup:YES

Upvotes: 2

Related Questions