开发者

Using predicate

I want to have a textfield for search which displays as in google's suggest,i.e When I type 'a' the table view should be filled with all words starting with 'a' retrieved from db.My question is how to use predicate for 开发者_运维百科querying from db.(as in 'a%' in mysql) Thanks in advance.


NSPredicate has the keywords CONTAINS, BEGINSWITH and ENDSWITH which are similar to like statement in sql. You can do the case insensitive comparison using the key characters c and d within square braces to specify case and diacritic insensitivity respectively (for example [c], [d] or [cd]).

You can read more on Predicate Programming Guide. Moreover, this Querying Core Data with Predicates - iPhone SO post has some discussion which I think will help you in this regard.

Note: Thanks to @Dave DeLong. His first comment below here, adds to this answer.


Apologies for being so terse, but everything you need to know about using an NSPredicate to retrieve data from your iOS app's database can be found in the Predicate Programming Guide by Apple available on their web site. Read all of it and play with the examples. If you then have more specific questions about using them, feel free to come back and ask.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜