I'm trying to use a lazy instantiation on a category but I'm stuck on how to do that without enter in a obvious infinity loop. Here some code for ilustrate:
@implementation User (Extras)
- (CacheControl *)cache
{
CacheControl *_cache = (CacheControl *)[self valueForKey:@"cache"];
if(!_cache){
[self setCache:(CacheControl *)[NSEntityDescription insertNewObjectForEntityForName:@"CacheControl" inManagedObjectContext:self.managedObjectContext]];
}
return _cache;
}
@end
Any Ideas how to address this situation or should I just don't do that at all?