@interface Model + (int) value; + (void) setValue:(int)val; @end @implementation Model static int value; + (int) value { @synchronized(self) { return value; } } + (void) setValue:(int)val { @synchronized(self) { value = val; } } @end
// Foo.h @interface Foo { } +(NSDictionary*) dictionary; // Foo.m +(NSDictionary*) dictionary { static NSDictionary* fooDict = nil; static dispatch_once_t oncePredicate; dispatch_once(&oncePredicate, ^{ // create dict }); return fooDict; }