Re: @selector not working with (id)anObject
Re: @selector not working with (id)anObject
- Subject: Re: @selector not working with (id)anObject
- From: Bill Bumgarner <email@hidden>
- Date: Sat, 11 Apr 2009 17:26:30 -0700
On Apr 11, 2009, at 5:20 PM, Trygve Inda wrote:
-(void)threadMethod:(id)anObject
{
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
SEL comp = (SEL)anObject;
... Do stuff ...
[self performSelectorOnMainThread:comp withObject:nil
waitUntilDone:NO];
[pool release];
}
This crashes during detachNewThreadSelector. How can I pass a method
to call
at the end of the thread processing as above?
There are a handful of issues here:
- a SEL is not an (id); if anything tries to -retain the SEL it is
going to crash
- in general, casting outside of casting up/down class hierarchies is
an indication that your code is wrong
If you really want to pass a selector around in a slot that normally
holds objects, use NSStringFromSelector() and NSSelectorFromString().
However, with that said, that is generally an atypical design
pattern. Not totally odd, but just not that typical. Raises a the
"what are you trying to do?" flag, though.
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