Theocacao
Leopard
Design Element
Comment on "Lazy Loading of KVO Observed Properties"
by Vincent Verville — Jun 17
Would this be appropriate? Let something else manage the lazily loaded resources and let it notify us when they're ready for assignment.

Note - I may have misunderstood your problem: Are you in fact looking for a way to avoid doing it this way?

-(NSImage*)image { if (image == nil) { // NSURL-style async handling of resources. // TTAppRez knows to ignores us if the request is (pending|ready). // will call [self RezResourceDidFinishLoading:] when ready. NSString* path = @"http://theocacao.com/images/leopard.png"; [TTAppRez loadResourceDataAt:path notifyingClient:self usingCache:YES]; } return image; } -(void)setImage:(NSImage*)newImage { NSImage* oldImage = image; image = [newImage retain]; [oldImage release]; } #pragma Resource Callbacks - (void)RezResourceDidFinishLoading:(TTAppRez *)sender { if ([self image] == nil) { NSImage* theImage = [[NSImage alloc] initWithData: [sender resourceDataUsingCache:YES]]; [self setImage:theImage]; [theImage release]; } }
Back to "Lazy Loading of KVO Observed Properties"
Design Element

Copyright © Scott Stevenson 2004-2015