ios - 在 NSMutableArray 中查找 NSMutableDictionary 的索引

标签 ios objective-c nsmutablearray nsmutabledictionary

我有一个带有特定keyvalue 的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/

相关文章:

ios - 以编程方式创建主从导航 Controller

objective-c - 如何实现事件时带有下划线文本的标签按钮

ios - 动态大小的 UILabel 紧跟 UIButton

ios - Swift 2.0 - NSMutableArray - 删除对象

xcode - 对 NSMutuableArray 进行排序

objective-c - 有没有办法排除某些文件提交到 iOS 应用商店

ios - Xcode 6 无法找到 .pch 文件,尽管它存在

ios - rx.tap 订阅已完成的按钮

objective-c - 类别。变量的可见性

ios - 具有 NSDictionary 项目的 NSMutableArray 中的独特项目?