objective c - How to access object for id -
hiho code-friends,
i created nsmutabledictionary "_favdictionary" picture-data inside. getting key current cell collection-view, contains integer named "key".
flamaincell *cell = (flamaincell *) sender.view; nsuinteger *key = cell.key; nsstring *instr = [nsstring stringwithformat:@"%lu", (unsigned long)key]; _favdictionary[instr] = storeimage; - (uiimage *)getfavouriteimages:(nsinteger)index{ return _favdictionary[index]; }
i beginner in objective-c , not find possibility access dictionary integer value in method "getfavouriteimages". error getting says "nsmutabledictionary doesn't respond objectatindexedsubscript".
can tell me how can access dictionary via integer?
first of all, if indexing integers, use nsarray
.
if want use nsdictionary
, don't have convert integers strings, can use nsnumber
instead.
flamaincell *cell = (flamaincell *) sender.view; nsuinteger *key = cell.key; nsnumber *innumber = @(key); _favdictionary[innumber] = storeimage; - (uiimage *)getfavouriteimages:(nsinteger)index{ return _favdictionary[@(index)]; }
if want use strings, have convert index
nsstring
too, before indexing:
- (uiimage *)getfavouriteimages:(nsinteger)index{ nsstring *stringindex = [nsstring stringwithformat:@"%@", @(index)]; return _favdictionary[stringindex]; }
Comments
Post a Comment