- (id)initFromKey:(NSString*)key {
NSString* path = [NSHomeDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"Library/Caches/%@", key]];
@try
{
self = [NSKeyedUnarchiver unarchiveObjectWithFile:path];
}
@catch (NSException * e)
{
[[NSFileManager defaultManager] removeItemAtPath:path error:nil];
return nil;
}
return self;
}
MyObject * object = [[MyObject alloc] initFromKey:@"TheKey"];
if (!object) {
object = [MyObject new];
}