In this sort of well-known code pattern for making a singleton with GCD:

+ (MyClass *) sharedInstance {
    static MyClass *sharedInstance = nil;
    static dispatch_once_t onceToken = 0;
    dispatch_once (&onceToken, ^{
        sharedInstance = [MyClass new];
    });
    return sharedInstance;
}

Why is the block permitted to assign to the variable sharedInstance outside the 
block? Evidently it is because "static" has an effect like "__block", in that 
it makes the variable outside the block assignable. But how, exactly? Is it 
some kind of side effect of being a local static? Thx - m.

--
matt neuburg, phd = m...@tidbits.com, <http://www.apeth.net/matt/>
A fool + a tool + an autorelease pool = cool!
Programming iOS 6! http://shop.oreilly.com/product/0636920029717.do

_______________________________________________

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to