Objective c 从具有多个实例的NSArray中筛选一个变量

Objective c 从具有多个实例的NSArray中筛选一个变量,objective-c,arrays,nspredicate,Objective C,Arrays,Nspredicate,我刚开始学习Objective-C,对自己的问题一无所知 我有一个类,我想从一个NSArray中筛选,该数组包含类的不同实例Employee实例的一个变量,name 雇员 main.m #导入 #导入“Employee.h” int main(int argc,const char*argv[]{ @自动释放池{ 员工*firstEmployee=[[Employee alloc]init]; [第一员工设置:35]; [firstEmployee setName:[NSString strin

我刚开始学习Objective-C,对自己的问题一无所知

我有一个类,我想从一个
NSArray
中筛选,该数组包含类的不同实例
Employee
实例的一个变量,
name

雇员

main.m

#导入
#导入“Employee.h”
int main(int argc,const char*argv[]{
@自动释放池{
员工*firstEmployee=[[Employee alloc]init];
[第一员工设置:35];
[firstEmployee setName:[NSString stringWithFormat:@“George”];
员工*secondEmployee=[[Employee alloc]init];
[第二员工设置:35];
[secondEmployee setName:[NSString stringWithFormat:@“Ivan”];
员工*thirdEmployee=[[Employee alloc]init];
[第三组员工年龄:35岁];
[ThirdEmployee集合名:[NSString stringWithFormat:@“Ivan”];
NSMutableArray*yesArray=
[NSMutableArray数组,其对象为:firstEmployee、secondEmployee、thirdEmployee、nil];
int i;
整数计数;
计数=[yesArray计数];
对于(i=0;i
要获取按姓名筛选的员工列表,请使用

NSPredicate *bPredicate1 = [NSPredicate predicateWithFormat:@"name BEGINSWITH[c] %@", @"I"];
NSArray *beginWith1 = [yesArray filteredArrayUsingPredicate:bPredicate1];
要获取仅包含员工姓名的数组,请使用

NSArray *namesOnly = [yesArray valueForKey:@"name"];
可以使用

NSPredicate *bPredicate2 = [NSPredicate predicateWithFormat:@"SELF BEGINSWITH[c] %@", @"I"];
NSArray *beginWith2 = [namesOnly filteredArrayUsingPredicate:bPredicate2];

如果您需要更多信息,请告诉我否则,如果答案有帮助,您可以单击复选标记“接受”。这标志着问题已经解决,并为您和答案的作者提供了一些“声誉点”。
NSPredicate *bPredicate1 = [NSPredicate predicateWithFormat:@"name BEGINSWITH[c] %@", @"I"];
NSArray *beginWith1 = [yesArray filteredArrayUsingPredicate:bPredicate1];
NSArray *namesOnly = [yesArray valueForKey:@"name"];
NSPredicate *bPredicate2 = [NSPredicate predicateWithFormat:@"SELF BEGINSWITH[c] %@", @"I"];
NSArray *beginWith2 = [namesOnly filteredArrayUsingPredicate:bPredicate2];