Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.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 对象数组到可变数组_Objective C_Nsmutablearray - Fatal编程技术网

Objective c 对象数组到可变数组

Objective c 对象数组到可变数组,objective-c,nsmutablearray,Objective C,Nsmutablearray,我有一个对象数组。对象包含三个值,id、name、value。我想从这个对象数组中解析名称,只想创建一个不同的名称数组…有人能帮我吗 int i; NSInteger *namesCount=[eCategories count]; //eCategories is an object array SubCategories *subCategoriesList=[[SubCategories alloc] init]; //SubCategories is a NSObject class

我有一个对象数组。对象包含三个值,id、name、value。我想从这个对象数组中解析名称,只想创建一个不同的名称数组…有人能帮我吗

int i; 
NSInteger *namesCount=[eCategories count]; //eCategories is an object array 
SubCategories *subCategoriesList=[[SubCategories alloc] init];
//SubCategories is a NSObject class containing cat_name,cat_id,cat_value. 
NSMutableArray *nameArray=[[NSMutableArray alloc]init]; 
for(i=0;i<namesCount;i++)
{ 
    subCategoriesList=[eCategories objectAtIndex:i]; 
    nameArray=subCategoriesList.cat_name; 
}
inti;
NSInteger*namesCount=[eCategorities count]//eCategories是一个对象数组
子类别*子类别列表=[[SubCategories alloc]init];
//子类别是一个NSObject类,包含cat_名称、cat_id和cat_值。
NSMutableArray*nameArray=[[NSMutableArray alloc]init];
对于(i=0;i

[objects valueForKeyPath: @"@distinctUnionOfArrays.name"]
当然,除非数组中的对象不是以“name”作为名称键的NSDictionary。您告诉我们的还不够。

NSArray有一个方法,可以在一条消息中完全实现您想要的功能

返回一个数组,该数组包含在每个数组对象上调用valueForKey:using键的结果

int i

NSInteger*namesCount=[eCategories count];//eCategories是一个对象数组

子类别*子类别列表=[[SubCategories alloc]init]

//子类别是一个NSObject类,包含cat_名称、cat_id和cat_值

NSMutableArray*nameArray=[[NSMutableArray alloc]init]

对于(i=0;i [nameArray addobject:subCategoriesList.cat_name];
}

int i;NSInteger*namesCount=[eCategories count];SubCategories*subCategoriesList=[[SubCategories alloc]init];//包含cat_名称、cat_id、cat_值的NSObject类。NSMutableArray*nameArray=[NSMutableArray alloc]init];用于(i=0;i您应该编辑您的答案,而不是将代码放在完全不可读的注释中。这次我已经为您完成了:)
NSArray* nameArray = [eCategories valueForKey: @"cat_name"];