Re: NSInvocation and methods with non-pointer parameters
Re: NSInvocation and methods with non-pointer parameters
- Subject: Re: NSInvocation and methods with non-pointer parameters
- From: Bill Bumgarner <email@hidden>
- Date: Mon, 02 Nov 2009 08:16:06 -0800
On Nov 2, 2009, at 2:17 AM, Jim Kang wrote:
> I seem to be able to use NSInvocation to execute methods that have
> parameters are pointers, like NSString* or NSDictionary*, but when I try to
> invoke a method with a parameter that is not a point, like this -
>
> (void)methodWithCGPoint: (CGPoint)pos;
>
> - I get an EXC_BAD_ACCESS when I run it with code like this:
>
> SEL sel = @selector(methodWithCGPoint:);
> if ([self respondsToSelector: sel])
> {
> NSMethodSignature *sig = nil;
> sig = [[self class] instanceMethodSignatureForSelector:sel];
> NSInvocation *invocation = nil;
> invocation = [NSInvocation
> invocationWithMethodSignature:sig];
> [invocation setTarget:self];
> [invocation setSelector:sel];
> [invocation setArgument:&pos atIndex:2];
> [invocation invoke];
> }
>
> What is the correct way to set the CGPoint argument to NSInvocation? The
> CGPoint can't get released before the invocation is finished, so [invocation
> retain] doesn't help.
If you are targeting Snow Leopard, use blocks instead... much more straightforward.
b.bum
_______________________________________________
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