• 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
Return value of performSelector:onThread:?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Return value of performSelector:onThread:?


  • Subject: Return value of performSelector:onThread:?
  • From: Abhi Beckert <email@hidden>
  • Date: Fri, 8 Oct 2010 15:49:42 +1000

Hi,

I have a background thread which needs the main thread to create an object (because part of the initializer isn't thread safe).

The performSelector: methods don't expose the return value of the message, even with waitUntilDone:YES. I'm not happy with my workaround, which is to use an instance variable:

@interface MyClass : NSObject {
	id tmpObj;
}
@end

@implementation MyClass

- (void)foobar
{
	[self performSelectorOnMainThread:@selector(createMyObj) withObject:nil waitUntilDone:YES];
	id myObj = tmpObj;
	[tmpObj autorelease];
	tmpObj = nil;

	// do stuff with myObj
}

- (void)createMyObj
{
	tmpObj = // create object

	[tmpObj retain]; // retain object, so it doesn't get auto-released
}

@end

Has anyone else got a cleaner technique? Perhaps provide an NSMutableDictionary to withObject: ?

- Abhi

- - -

Kind Regards,
Abhi Beckert

Senior Programmer
Precedence - Websites. Hosting. Marketing.
1300 363 160
http://precedence.com.au

_______________________________________________

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: Return value of performSelector:onThread:?
      • From: Seth Willits <email@hidden>
    • Re: Return value of performSelector:onThread:?
      • From: Kyle Sluder <email@hidden>
  • Prev by Date: create multiple Custom Views
  • Next by Date: Re: Problem using dictionary
  • Previous by thread: create multiple Custom Views
  • Next by thread: Re: Return value of performSelector:onThread:?
  • Index(es):
    • Date
    • Thread