这些是一些辅助类,用于处理存储和检索标准数据结构
或者将此存储库中的 THCache/
目录复制到您的项目中。
使用 NSString
- (void)StringStorage {
[THCacher storeItemsToCache:@"ItemToStore" withKey:@"testStringStorageKey"];
NSString *itemToStore = [THCacher restoreItemsFromCacheWithKey:@"testStringStorageKey"]];
NSError *err;
[THCacher removeItemsFromCacheWithKey:@"testStringStorageKey"error:&err]
}
使用 NSArray
- (void)NSArrayStorage {
NSArray *array = @[@"ItemToStore", @"ItemToStore"];
[array storeArrayToCacheWithKey:@"testNSArrayStorageKey"];
array2 = [[NSArray alloc] initArrayFromCacheWithKey:@"testNSArrayStorageKey"];
NSError *err;
[array removeArrayFromCacheWithKey:@"testNSArrayStorageKey"error:&err];
}
使用 NSData
- (void)NSDataStorage {
NSData *data = [@"ItemToStore" dataUsingEncoding:NSUTF8StringEncoding];
[data storeDataToCacheWithKey:@"testNSDataStorageKey"];
[data initDataFromCacheWithKey:@"testNSDataStorageKey"];
NSError *err;
[data removeDataFromCacheWithKey:@"testNSDataStorageKey"error:&err];
}
使用 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];
}
...是非常受欢迎的。
此项目的源代码可在标准 MIT 许可证下获得。请参阅许可证文件。