Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 如何从NSArray中的NSDictionary获取值_Objective C_Ios_Nsarray_Nsdictionary - Fatal编程技术网

Objective c 如何从NSArray中的NSDictionary获取值

Objective c 如何从NSArray中的NSDictionary获取值,objective-c,ios,nsarray,nsdictionary,Objective C,Ios,Nsarray,Nsdictionary,我想知道是否有可能从NSArray中的NSDictionary中的所需键获取值 例如: NSArray *array = @[ @{@"title" : @"title 1", @"description" : @"description 1"}, @{@"title" : @"title 2", @"description" : @"description 2"}, @{@"title" : @"title 3", @"description" : @"description 3"} ];

我想知道是否有可能从
NSArray
中的
NSDictionary
中的所需键获取值

例如:

NSArray *array = @[ @{@"title" : @"title 1", @"description" : @"description 1"},
@{@"title" : @"title 2", @"description" : @"description 2"}, 
@{@"title" : @"title 3", @"description" : @"description 3"} ];
我想获取(无需创建新的
NSMutableArray
)我的
NSArray
中的所有标题。也许我做错了什么,而我的方法完全不好

我知道我可以创建一个新类并具有两个属性(title、desc),但有没有一种方法不创建类或创建一个新的
NSMutableArray
并遍历我的数组?

简单:

NSArray *titles = [array valueForKey:@"title"];

这是因为
NSArray
valueForKey:
实现返回一个新数组,其中包含数组中每个对象的
valueForKey:
结果。

您是否尝试通过调用“NSDictionary*dict=[array objectAtIndex:0];”来获取对字典的引用然后打电话给dict valueForKey?我手头没有这些参考资料,但它应该可以工作。iOS开发者还不能使用新的华丽语法。从“最新信息”页面:@dasblinkenlight是的,只需要Xcode 4.4.@omz不是苹果公司所说的。我在上面的评论中贴了一个链接。@omz哇,很高兴知道,谢谢!我想下次我不应该信任他们的文档:)如何在
Swift
中使用此功能?