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 ?
In the case that you cannot alter the target-method signature to accept a NSNumber
in place of a BOOL
you can use NSInvocation
instead of performSelector
:
MyTargetClass* myTargetObject; BOOL myBoolValue = YES; // or NO NSMethodSignature* signature = [[myTargetObject class] instanceMethodSignatureForSelector: @selector( myMethodTakingBool: )]; NSInvocation* invocation = [NSInvocation invocationWithMethodSignature: signature]; [invocation setTarget: myTargetObject]; [invocation setSelector: @selector( myMethodTakingBool: ) ]; [invocation setArgument: &myBoolValue atIndex: 2]; [invocation invoke];
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];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With