> 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.
I have a thread. Depending on how it is called, I need to do something different at the end of the main processing so I wanted to pass a selector into the thread so it could call it when it was ready. I could just pass an NSNumber and do case1, case2 etc, but thought it'd be nice to just do the equivalent of passing a function pointer. So one of these needs to be called: [self performSelectorOnMainThread:@selector(cacheComplete) withObject:nil waitUntilDone:NO]; [self performSelectorOnMainThread:@selector(initComlete) withObject:nil waitUntilDone:NO]; Thoughts? _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com