Created
November 26, 2009 14:49
-
-
Save lukeredpath/243496 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "EGOCache.h" | |
@interface EGOCache (Plist) | |
- (NSData*)plistForKey:(NSString*)key; | |
- (void)setPlist:(id)plistObject forKey:(NSString*)key; | |
- (void)setPlist:(id)plistObject forKey:(NSString*)key withTimeoutInterval:(NSTimeInterval)timeoutInterval; | |
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "EGOCache.h" | |
#import "EGOCache+Plist.h" | |
@implementation EGOCache (Plist) | |
- (NSData*)plistForKey:(NSString*)key; | |
{ | |
NSData *plistData = [self dataForKey:key]; | |
return [NSPropertyListSerialization | |
propertyListFromData:plistData | |
mutabilityOption:NSPropertyListImmutable | |
format:nil | |
errorDescription:nil]; | |
} | |
- (void)setPlist:(id)plistObject forKey:(NSString*)key; | |
{ | |
[self setPlist:plistObject forKey:key withTimeoutInterval:60 * 60 * 24]; | |
} | |
// XML format would produce cache files that are human-readable but at the | |
// expense of performance, so I felt binary format was best. | |
- (void)setPlist:(id)plistObject forKey:(NSString*)key withTimeoutInterval:(NSTimeInterval)timeoutInterval; | |
{ | |
NSString *errorString; | |
NSData *plistData = [NSPropertyListSerialization | |
dataFromPropertyList:plistObject | |
format:NSPropertyListBinaryFormat_v1_0 | |
errorDescription:&errorString]; | |
[self setData:plistData forKey:key withTimeoutInterval:timeoutInterval]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment