I don't know KVO, but remember that that static bool is static across instances as well
You're right, but it doesn't matter if all of this is being done in a single thread since only one getter is ever being called at a time. The example is simplistic by design. Here's an example for what you suggest (the setter should be the same as above):
by Scott Stevenson — Jun 16
You're right, but it doesn't matter if all of this is being done in a single thread since only one getter is ever being called at a time. The example is simplistic by design. Here's an example for what you suggest (the setter should be the same as above):
@interface MyClass : NSObject { NSImage myImage; BOOL myImageIsBeingSet; } @end @implementation class - (id)init { if ( self = [super init] ) { myImageIsBeingSet = NO; } return self; } - (NSImage*)myImage { if ( myImage == nil && myImageIsBeingSet == NO ) { myImageIsBeingSet = YES; [self setMyImage:[self fetchImageFromDisk]]; myImageIsBeingSet = NO; } return myImage; } @end