1
我將NSString保存爲NSCache,但在NSLog中給我(null)。NSCache一直給我(null)
我有這樣的代碼保存在NSCache後,我在viewDidLoad中初始化它
cache=[[NSCache alloc]init];
然後,我有一個名叫並保存函數對象
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:1 inSection:1];
NSString *res = [cache objectForKey:indexPath];
if (!res) {
[email protected]"1";
[cache setObject:res forKey:indexPath];
}
然後我檢查是這樣的:
NSString *res = [cache objectForKey:indexPath];
if (!res) {
[email protected]"1";
[cache setObject:res forKey:indexPath];
}
可惜...
NSLog("%@",res); //always it gives me (null)
任何人有過這個問題嗎?任何幫助讚賞。
你在哪裏做記錄?你是否檢查過初始值不是NSNull?複製密鑰是否有所作爲(NSCache默認情況下不復制密鑰)? –