【发布时间】:2012-02-24 00:14:16
【问题描述】:
我希望为新闻创建一个缓存管理器类,它也可以用于其他 iPhone 项目。我的缓存管理器将支持 JSON 数据的缓存,即文本和图像并将其本地存储在 iPhone 中。这背后的主要思想是使应用程序能够访问缓存的数据,从而减少网络活动。
我正在考虑通过以下方式实现这个东西:
Sqlite 数据库,即获取所有数据并存储
将此数据添加到某个 .plist 文件中
核心数据
我尝试将此代码用于第二个解决方案:
NSString *plistPath = [self Return_PlistPathCreation]; // Method to creat the JSON file locaally under Documents
NSMutableDictionary *dict = [[NSMutableDictionary alloc]init];
[dict setValue:newsArray forKey:@"homenews"]; //newsArray is the array containing objects parsed from the JSON webservice
NSLog(@"JSON representation for dictionary is %@",[dict JSONRepresentation]); //it prints perfectly
[[dict JSONRepresentation] writeToFile:plistPath atomically:YES encoding:NSASCIIStringEncoding error:nil]; //Not not able to write it within the file
上面的代码有什么问题?
那么,根据应用程序的性能和响应能力,哪一种方式更适合存储缓存数据?虽然我对新想法持开放态度,但除了上述之外还有其他方法吗?
【问题讨论】:
标签: iphone sqlite ios4 core-data plist