One Quickie


Performing one-time initialization (Blocks->General)
You can use libdispatch / Grand Central Dispatch, to execute a block that must run once, and only once, no matter how many threads are knocking at its door.
+ (void) initialize {
    static dispatch_once_t init_predicate;

    dispatch_once (&init_predicate, ^{ 
            CGColorSpaceRef rgbSpace = CGColorSpaceCreateDeviceRGB ();

            for (int i = 0; i < 7; i++) {
                CGFloat components[] = { rawZoneColors[i]._red,
                                         rawZoneColors[i]._green,
                                         rawZoneColors[i]._blue,
                                         rawZoneColors[i]._alpha };
                zoneColors[i] = CGColorCreate (rgbSpace, components);
            }
        });

} // initialize



borkware home | products | miniblog | rants | quickies | cocoaheads
Advanced Mac OS X Programming book

webmonster@borkware.com