Skip to content

Instantly share code, notes, and snippets.

@shnhrrsn
Created December 15, 2010 23:11
Show Gist options
  • Save shnhrrsn/742758 to your computer and use it in GitHub Desktop.
Save shnhrrsn/742758 to your computer and use it in GitHub Desktop.
#import "EGOCache.h"
@interface EGOCache (NSArray)
- (void)setArray:(NSArray*)array forKey:(NSString*)key;
- (void)setArray:(NSArray*)array forKey:(NSString*)key withTimeoutInterval:(NSTimeInterval)timeoutInterval;
- (NSArray*)arrayForKey:(NSString*)key;
@end
#import "EGOCache+NSArray.h"
@implementation EGOCache (NSArray)
- (void)setArray:(NSArray*)array forKey:(NSString*)key {
[self setArray:array forKey:key withTimeoutInterval:self.defaultTimeoutInterval];
}
- (void)setArray:(NSArray*)array forKey:(NSString*)key withTimeoutInterval:(NSTimeInterval)timeoutInterval {
[self setData:[NSKeyedArchiver archivedDataWithRootObject:array] forKey:key withTimeoutInterval:timeoutInterval];
}
- (NSArray*)arrayForKey:(NSString*)key {
NSData* data = [self dataForKey:key];
if(data) {
return [NSKeyedUnarchiver unarchiveObjectWithData:data];
} else {
return nil;
}
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment