I am new to NSCache, I want to cache the response data and use it. So my [cache setobject]
is in class A and I need to get it from class B using [cache objectForKey]
. But it is always NULL
.It works in same class as below..
我是NSCache的新手,我想缓存响应数据并使用它。所以我的[cache setobject]在A类中,我需要使用[cache objectForKey]从B类中获取它。但它总是NULL。它在同一个类中工作如下..
NSURL *url = [NSURL URLWithString:@"http://ios.eezytutorials.com/sample-files/sample-dictionary-plist.plist"];
NSDictionary *dict = [[NSDictionary alloc]initWithContentsOfURL:url];
NSCache *cache = [[NSCache alloc]init];
[cache setObject:dict forKey:url];
NSLog(@"%@",[cache objectForKey:url]);
How to get that from different class?
如何从不同的班级获得?
1 个解决方案
#1
NSCache is not a singleton or shared instance. If you want to use the contents of a specific instance, you could place your NSCache instance on AppDelegate or create your own singleton class to manage it.
NSCache不是单例或共享实例。如果要使用特定实例的内容,可以将NSCache实例放在AppDelegate上,也可以创建自己的单例类来管理它。
#1
NSCache is not a singleton or shared instance. If you want to use the contents of a specific instance, you could place your NSCache instance on AppDelegate or create your own singleton class to manage it.
NSCache不是单例或共享实例。如果要使用特定实例的内容,可以将NSCache实例放在AppDelegate上,也可以创建自己的单例类来管理它。