Re: BOOL parameter passed as nil object
Re: BOOL parameter passed as nil object
- Subject: Re: BOOL parameter passed as nil object
- From: Charles Srstka <email@hidden>
- Date: Tue, 19 Apr 2016 15:49:12 -0500
> On Apr 19, 2016, at 2:07 PM, Jens Alfke <email@hidden> wrote:
>
> Anyway, I can’t remember if anyone gave a solution to the question. The right way to do this is to create a new method that takes an NSNumber, and invoke _that_ method using the delayed-perform, after boxing the BOOL. Then the new method can call the original method with the unboxed BOOL value.
Or, use NSInvocation:
BOOL someBool = …;
SEL selector = @selector(myMethod:);
NSMethodSignature *sig = [self methodSignatureForSelector:selector];
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:sig];
[invocation setArgument:&someBool atIndex:2];
[invocation invokeWithTarget:self];
Not pretty, but it works.
The *best* solution is probably to see if there’s a way to move away from performSelector: in the first place, possibly by moving towards a blocks-based approach. This is more future-proof, too, since a lot of this Obj-C dynamic stuff isn’t available in Swift, so you’ll have to redesign it all if you decide to go that direction at some point.
Charles
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden