These are some helper classes to handle storing and retrieving of standard data structures
Install with CocoaPods by adding the following to your Podfile:
platform :ios, '6.1'
pod 'THCache', '~> 0.9.1'
Note: We follow http://semver.org for versioning the public API.
Or copy the THCache/
directory from this repo into your project.
With NSString
- (void)StringStorage {
[THCacher storeItemsToCache:@"ItemToStore" withKey:@"testStringStorageKey"];
NSString *itemToStore = [THCacher restoreItemsFromCacheWithKey:@"testStringStorageKey"]];
NSError *err;
[THCacher removeItemsFromCacheWithKey:@"testStringStorageKey"error:&err]
}
With NSArray
- (void)NSArrayStorage {
NSArray *array = @[@"ItemToStore", @"ItemToStore"];
[array storeArrayToCacheWithKey:@"testNSArrayStorageKey"];
array2 = [[NSArray alloc] initArrayFromCacheWithKey:@"testNSArrayStorageKey"];
NSError *err;
[array removeArrayFromCacheWithKey:@"testNSArrayStorageKey"error:&err];
}
With NSData
- (void)NSDataStorage {
NSData *data = [@"ItemToStore" dataUsingEncoding:NSUTF8StringEncoding];
[data storeDataToCacheWithKey:@"testNSDataStorageKey"];
[data initDataFromCacheWithKey:@"testNSDataStorageKey"];
NSError *err;
[data removeDataFromCacheWithKey:@"testNSDataStorageKey"error:&err];
}
With NSDictionary
- (void)testNSDictionaryStorage {
NSDictionary *dictionary = @{@"Key1" : @"ItemToStore", @"Key2" : @"ItemToStore"};
[dictionary storeDictionaryToCacheWithKey:@"testNSDictionaryStorageKey"];
NSDictionary *dictionary2 = [[NSDictionary alloc] initDictionaryFromCacheWithKey:@"testNSDictionaryStorageKey"];
NSError *err;
[dictionary removeDictionaryFromCacheWithKey:@"testNSDictionaryStorageKey"error:&err];
}
#Contributions
...are really welcome.
Source code of this project is available under the standard MIT license. Please see the license file.