NSCache を拡張し、以下のように Singleton クラスを作成しました
+(instancetype)sharedDataCache {
if (!sharedDataCache) {
sharedDataCache = [[QDataCache alloc] init];
[sharedDataCache setTotalCostLimit:19999];
[sharedDataCache setCountLimit:15];
[[NSNotificationCenter defaultCenter] addObserver:sharedDataCache selector:@selector(removeAllObjects) name:UIApplicationDidReceiveMemoryWarningNotification object:nil];
}
return sharedDataCache;
}
1 つのクラスでのオブジェクトの設定:
[_cache setObject:receivedData forKey:[[connection currentRequest]URL]];
および他のクラスのオブジェクトの取得:
image = [UIImage imageWithData:[_caches objectForKey:keyString]];//keystring is the url
両方のキーはログで同じですが、NULL を取得しています :( .「IF I HARDCODE THE KEY WITH SAME STRING IT IS WORKING FINE」.