Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Re: Create an NSCharacterSet constant
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Create an NSCharacterSet constant



On Sun, 1 Nov 2009 21:29:25 -0800, Kyle Sluder <email@hidden> 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@hidden, <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@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



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.