我有一个属性为personName,lastName和age的通用人员对象。我将用户输入存储到一个NSMutableArray中,我想通过他/她的名字在数组中找到一个下面的内容。我试图找到一堆不同的解决方案,但没有一个真的有效。在NSMutableArray中按名称查找对象
这是我的main.m
@autoreleasepool {
char answer;
char locatePerson[40];
//Create mutable array to add users for retrieval later
NSMutableArray *people = [[NSMutableArray alloc] init];
do{
Person *newPerson = [[Person alloc]init];
[newPerson enterInfo];
[newPerson printInfo];
[people addObject:newPerson];
NSLog(@"Would you like to enter another name?");
scanf("\n%c", &answer);
}while (answer == 'y');
NSLog(@"Are you looking for a specific person?");
scanf("%c", locatePerson);
//This is where I need help
int idx = [people indexOfObject:]
}
这是很基本的,但我是新来的Objective-C和我想尝试并找到该用户名。我见过的解决方案使用了indexesOfObjectsPassingTest
方法。但我想知道如果我不能像我那样用indexOfObject
方法来定位一个人的名字吗?
任何帮助表示赞赏。
你知道,你可以写一个循环来搜索'people'数组。 –