Skip to content
This repository
Browse code

Merge branch 'master' of git://gist.github.com/243496

  • Loading branch information...
commit c3fefe23db09be822b61d0fd62bfdaa310c5c013 2 parents 243109a + 03484b3
Shaun Harrison authored November 26, 2009
9  EGOCache+Plist.h
... ...
@@ -0,0 +1,9 @@
  1
+#import "EGOCache.h"
  2
+
  3
+@interface EGOCache (Plist)
  4
+
  5
+- (NSData*)plistForKey:(NSString*)key;
  6
+- (void)setPlist:(id)plistObject forKey:(NSString*)key;
  7
+- (void)setPlist:(id)plistObject forKey:(NSString*)key withTimeoutInterval:(NSTimeInterval)timeoutInterval;
  8
+
  9
+@end
35  EGOCache+Plist.m
... ...
@@ -0,0 +1,35 @@
  1
+#import "EGOCache.h"
  2
+#import "EGOCache+Plist.h"
  3
+
  4
+@implementation EGOCache (Plist)
  5
+
  6
+- (NSData*)plistForKey:(NSString*)key;
  7
+{  
  8
+  NSData *plistData = [self dataForKey:key];
  9
+  return [NSPropertyListSerialization 
  10
+    propertyListFromData:plistData 
  11
+        mutabilityOption:NSPropertyListImmutable 
  12
+                  format:nil 
  13
+        errorDescription:nil];
  14
+}
  15
+
  16
+- (void)setPlist:(id)plistObject forKey:(NSString*)key;
  17
+{
  18
+  [self setPlist:plistObject forKey:key withTimeoutInterval:60 * 60 * 24];
  19
+}
  20
+
  21
+// XML format would produce cache files that are human-readable but at the
  22
+// expense of performance, so I felt binary format was best.
  23
+
  24
+- (void)setPlist:(id)plistObject forKey:(NSString*)key withTimeoutInterval:(NSTimeInterval)timeoutInterval;
  25
+{
  26
+  NSString *errorString;
  27
+  NSData *plistData = [NSPropertyListSerialization 
  28
+    dataFromPropertyList:plistObject 
  29
+                  format:NSPropertyListBinaryFormat_v1_0 
  30
+        errorDescription:&errorString];
  31
+  
  32
+  [self setData:plistData forKey:key withTimeoutInterval:timeoutInterval];
  33
+}
  34
+
  35
+@end

0 notes on commit c3fefe2

Please sign in to comment.
Something went wrong with that request. Please try again.