Objective c IOS:NSpredicate,带数组和搜索栏

Objective c IOS:NSpredicate,带数组和搜索栏,objective-c,nspredicate,Objective C,Nspredicate,我是IOS编程新手,我需要你的帮助。 首先,我有一个表视图,其中包含NSMutablearray“rec”的对象。 我插入了一个UISearchBar,目的是从我想要的记录中找到每个对象。。 当我尝试输入搜索栏时,它崩溃了,下面的消息出现在日志文件中 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Can't use in/contains operator with col

我是IOS编程新手,我需要你的帮助。 首先,我有一个表视图,其中包含
NSMutablearray
“rec”的对象。 我插入了一个
UISearchBar
,目的是从我想要的记录中找到每个对象。。 当我尝试输入搜索栏时,它崩溃了,下面的消息出现在日志文件中

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Can't use in/contains operator with collection <Person: 0x8e20b10> (not a collection)'
}

}

我很困惑。。。
请帮帮我

错误消息表示数组包含
Person
对象,而不仅仅是 串。在这种情况下,您必须指定应用于搜索的
Person
类的属性,例如:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"lastName CONTAINS[cd] %@", searchText];
-(void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope {
// Update the filtered array based on the search text and scope.
// Remove all objects from the filtered search array
[self.searcharray removeAllObjects];
// Filter the array using NSPredicate
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"self contains[cd] %@",searchText];
_searcharray = [NSMutableArray arrayWithArray:[_recs filteredArrayUsingPredicate:predicate]];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"lastName CONTAINS[cd] %@", searchText];