iosobjective-ciphoneselectornsinvocation

Objective-C: How to call performSelector with a BOOL typed parameter?


Is there any way to send a BOOL in selector ?

[self performSelector:@selector(doSomething:) withObject:YES afterDelay:1.5];

Or I should use NSInvocation? Could somebody write a sample please ?


Solution

  • you can use NSNumber to wrap bools types:

    BOOL myBool = YES;
    NSNumber *passedValue = [NSNumber numberWithBool:myBool];
    [self performSelector:@selector(doSomething:) withObject:passedValue afterDelay:1.5];
    

    and in the selector, to get the bool value, you use:

    BOOL value = [recievedObject boolValue];