缓存cache

缓存cahche

存入

在网络请求函数中写:

1
2
3
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:dataarray];
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@“这个地方可以吧API作为key”];
[[NSUserDefaults standardUserDefaults] setObject:data forKey:@“这个地方可以吧API作为key”];

取出

1
2
3
4
5
NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:API_TOPIC_RCMD_GETRCMD];
NSArray *arraycache = [NSKeyedUnarchiver unarchiveObjectWithData:data];
if (arraycache.count) {
self.recommendArray = arraycache;
}