我有一個問題,我使用NSMutableDictionaries從NSDictionary返回值。iOS不兼容的指針類型從NSMutableDictionary返回NSDictionary
這裏是警告消息:
不相容指針類型返回 '的NSDictionary *' 從函數 與結果類型 '的NSMutableDictionary *'
下面是代碼:
- (NSMutableDictionary *)dictionaryWithContentsAtPath:(NSString *)path
{
if ([path rangeOfString:@"/SessionStore"].location == 0)
{
return [_inMemoryCache objectForKey:[path stringByReplacingCharactersInRange:NSMakeRange(0, 13) withString:@""]];
}
if ([path rangeOfString:@"/PermanentStore"].location == 0)
{
return [NSDictionary dictionaryWithContentsOfFile:[self.persistentStoragePath stringByAppendingPathComponent:[path substringFromIndex:15]]];
}
return nil;
}
請幫我解決這個警告。
如果你返回一個'NSDictionary'('return [NSDictionary ZzZ')),你爲什麼要設置一個'NSMutableDictionary'作爲你的方法的返回值(there:' - (NSMutableDictionary *)dictionaryZzZ')? – Larme 2014-12-02 09:33:18
你應該返回[NSMutableDictionary dictionaryWithDictionary:_your_NSDictionary_]; – larva 2014-12-02 09:35:36