• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: @selector not working with (id)anObject
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: @selector not working with (id)anObject
      • From: Trygve Inda <email@hidden>
References: 
 >@selector not working with (id)anObject (From: Trygve Inda <email@hidden>)

  • Prev by Date: @selector not working with (id)anObject
  • Next by Date: Re: @selector not working with (id)anObject
  • Previous by thread: @selector not working with (id)anObject
  • Next by thread: Re: @selector not working with (id)anObject
  • Index(es):
    • Date
    • Thread