我有一个带有特定key
和value
的NSMutableDictionary。这个字典在 NSMutableArray 中。我想用数组内某个索引处的特定键更新字典。我想找到这个字典对象的索引。目前,我的词典索引为 0,而我的 editingIndexPath
为 1,属于 NSIndexPath 类型,因此 editingIndexPath.row
对我没有帮助。
我的代码如下:
//UpdatedDateAndTime is the NSMutableArray.
//selectedDay is a NSString object.
//dateKeySelected is also a string key.
[[updatedDateAndTime objectAtIndex:editingIndexPath.row] setObject:selectedDay forKey:dateKeySelected];
我的问题是我想获得找到的字典的正确索引。
最佳答案
答案曾经是一个带有计数器的 for 循环,但你很幸运:NSArray 有一个新方法,indexOfObject: ,这应该可以很好地解决问题:
NSUInteger i = [myArray indexOfObject:@{myKey:myValue}];
swift :index(of:)
关于ios - 在 NSMutableArray 中查找 NSMutableDictionary 的索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40002969/