xcode - iOS Incompatible pointer types returning NSDictionary from NSMutableDictionary -
i'm having issue use nsmutabledictionaries returns values nsdictionary.
here warning message:
incompatible pointer types returning 'nsdictionary *' function result type 'nsmutabledictionary *'
here code:
- (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; }
please me how resolve warning.
you need ensure you're returning right type. method states it's returning nsmutabledictionary
, returns nsdictionary
.
try instead:
- (nsmutabledictionary*)dictionarywithcontentsatpath:(nsstring*)path { if ([path rangeofstring:@"/sessionstore"].location == 0) { return [[_inmemorycache objectforkey:[path stringbyreplacingcharactersinrange:nsmakerange(0, 13) withstring:@""]] mutablecopy]; } if ([path rangeofstring:@"/permanentstore"].location == 0) { return [nsmutabledictionary dictionarywithcontentsoffile:[self.persistentstoragepath stringbyappendingpathcomponent:[path substringfromindex:15]]]; } return nil; }
note: added call mutablecopy
turn literal nsdictionary
mutable version, , in second case, used called dictionarywithcontentsoffile
method on nsmutabledictionary
subclass instead of nsdictionary
parent class.
Comments
Post a Comment