On Sun, 1 Nov 2009 21:29:25 -0800, Kyle Sluder <[email protected]> said:
>I'm partial to the following construct:
>
>+ (Foo *)sharedFoo {
>  static Foo *sharedFoo;
>  dispatch_once_t once;
>  dispatch_once(&once, ^{ sharedFoo = [[foo alloc] init]; }
>  return sharedfoo;
>}

Why (I'm really asking, not arguing; I don't know anything about GCD) is
this better than the traditional:

+ (Foo*) sharedFoo {
   static Foo* sharedFoo = nil;
   if (nil == sharedFoo) sharedFoo = [[Foo alloc] init];
   return sharedFoo;
}

m.

-- 
matt neuburg, phd = [email protected], <http://www.tidbits.com/matt/>
A fool + a tool + an autorelease pool = cool!
AppleScript: the Definitive Guide - Second Edition!
http://www.tidbits.com/matt/default.html#applescriptthings



_______________________________________________

Cocoa-dev mailing list ([email protected])

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 [email protected]

Reply via email to