NSPredicate是SQL的LIKE的等价物 [英] NSPredicate that is the equivalent of SQL's LIKE
本文介绍了NSPredicate是SQL的LIKE的等价物的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在寻找一种方法使用 NSPredicate
设置 LIKE
条件来获取对象。除此之外, OR
也是有用的。我想做一些事情,如果用户搜索James,我可以写一个 NSPredicate
,它将等效于:
select * from users where firstname LIKE'%James%'OR lastname LIKE'%James%';
解决方案
NSString * _mySearchKey = @James;
NSPredicate * _myPredicate = [NSPredicate predicateWithFormat:@(firstname CONTAINS [cd]%@)OR(lastname CONTAINS [cd]%@),_mySearchKey,_mySearchKey];
I'm looking for a way to use
NSPredicate
to set aLIKE
condition to fetch objects. In addition to that, anOR
would be useful as well. I'm trying to do something where if a user searches "James" I can write anNSPredicate
that will do the equivalent of:select * from users where firstname LIKE '%James%' OR lastname LIKE '%James%';
解决方案NSString *_mySearchKey = @"James"; NSPredicate *_myPredicate = [NSPredicate predicateWithFormat:@"(firstname CONTAINS[cd] %@) OR (lastname CONTAINS[cd] %@)", _mySearchKey, _mySearchKey];
这篇关于NSPredicate是SQL的LIKE的等价物的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文