Ron Ron - 1 year ago 82
iOS Question

Finding index of NSMutableDictionary inside an NSMutableArray

I have an NSMutableDictionary with a specific

. This dictionary is inside an NSMutableArray. I want to update the dictionary with a specific key which is at a certain index inside the array. I want to find the index of this dictionary object. Currently, my dictionary is at index 0 and my
is 1 which is of NSIndexPath type, so
doesn't help me.

My code is as follows:

//UpdatedDateAndTime is the NSMutableArray.
//selectedDay is a NSString object.
//dateKeySelected is also a string key.

[[updatedDateAndTime objectAtIndex:editingIndexPath.row] setObject:selectedDay forKey:dateKeySelected];

My problem is that I want to get the right index of the dictionary that is found.

Answer Source

The answer used to be a for loop with a counter, but you're in luck: NSArray has a new method, indexOfObject:, which should do the trick just fine:

NSUInteger i = [myArray indexOfObject:@{myKey:myValue}];

Swift: index(of:)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download