最近在做缓存,要把app应用中首页的文章列表里面的数据,保存起来。点击对应的tableViewCell,显示对应的文章列表数据。开始尝试使用了 coredata,然后又用了sqlite3,最后发
现用plist 是比较简单方便的。
代码如下便于以后参考:
首先是获得纱盒目录的路径 :
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString *path=[paths objectAtIndex:0];
NSString *filename=[path stringByAppendingPathComponent:@"homePageViewController.plist"];
从plist文件中读取内容的方法
NSDictionary* dic2 = [NSDictionary dictionaryWithContentsOfFile:filename];
向plist文件中写入内容的方法
[dic writeToFile:filename atomically:YES];
进入第二个界面的时候,要对plist文件进行增加操作,上面的方法