【发布时间】:2011-06-29 11:36:21
【问题描述】:
我有一个充满 NSDictionary 对象的 NSArray,每个 NSDictionary 里面都有一个唯一的 ID。我想根据 ID 查找特定词典,并在我自己的词典中获取该词典的所有信息。
myArray 包含:
[index 0] myDictionary object
name = apple,
weight = 1 pound,
number = 294,
[index 1] myDictionary object
name = pear,
weight = .5 pound,
number = 149,
[index 3] myDictionary object (etc...)
我想获取第二个字典对象的名称和权重(我不知道对象的索引...如果只有两个字典,我可以从[myArray objectAtIndex:1] 制作字典)
假设我知道数字 149。我怎样才能将第二个 myDictionary 对象从 myArray 中取出到新的 NSDictionary 中?
【问题讨论】:
-
嗯...可能是 stackoverflow.com/questions/2457495 和 stackoverflow.com/questions/958622 的欺骗,但我仍然不一定喜欢这些答案中的方法(虽然还没有深入阅读)。我目前在 Core Data 中的整个应用程序中执行三到四个查询,但我宁愿只能够使用一组 dicts 完成所有操作。我应该在这里使用 NSPredicate 吗?
-
myDictionary对象实际上是NSDictionary对象还是自定义对象? -
我认为@Chuck 的回答在这种情况下是正确的,我确实不知道您可以在这里使用 KVC/
NSPredicate,但我认为我错了。
标签: iphone objective-c nsarray nsdictionary