小编Dav*_*d P的帖子

如何为NSPredicate连接两个字符串,即firstname和lastname

我有一个Person具有两个NSString属性的Object ; firstName and lastName.我目前正在使用NSPredicate这样的:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(firstName contains[cd] %@) OR (lastName contains[cd] %@)", searchText, searchText];
Run Code Online (Sandbox Code Playgroud)

所以,例如,说我正在寻找这个名字"John Smith".在我的搜索栏中,如果我输入"Joh",John Smith则会显示为选项.这很好,但如果我输入"John Sm"它将变为空白.

我如何加入firstName和lastName,predicate如果我正在搜索,"John Sm"那么John Smith仍然会显示为一个选项.

我希望这是有道理的.谢谢.

编辑:为了进一步澄清,我正在使用SearchDisplayController委托方法:

-(void)filterContentForSearchText:(NSString *)searchText scope:(NSString *)scope;
Run Code Online (Sandbox Code Playgroud)

我正在使用predicate这样的:

newArray = [personObjectArray filteredArrayUsingPredicate:predicate];
Run Code Online (Sandbox Code Playgroud)

iphone objective-c nsstring nspredicate ios

14
推荐指数
1
解决办法
4292
查看次数

标签 统计

ios ×1

iphone ×1

nspredicate ×1

nsstring ×1

objective-c ×1