objective c - How can I make a nsdictionary out of it with string objects as the key and array of postion as the object for the key -
objective c - How can I make a nsdictionary out of it with string objects as the key and array of postion as the object for the key -
basically have array of nsstring objects 'a',l,l,a,h,a,b,a,d. output should nsdictionary 0,3,5,7 key a, 1,2 key l 4 key h 6 key b 8 key d.
it's simple for-in loop little this:
- (nsdictionary*)dictionaryfromarrayofstrings:(nsarray*)array { int idx = 1; nsmutabledictionary *retval = @{}.mutablecopy; (nsstring *char in array) { //reverse them dictionary of nsnumbers set of nsstring keys [retval setobject:char forkey:@(idx)]; idx++; } homecoming retval; }
objective-c nsarray nsdictionary nsrange
Comments
Post a Comment