ios - Fetch Realm objects that contain parameter -


i have realm database filled restaurant objects have url parameter. i'd fetch objects url contains user has typed in uitextfield.

nspredicate *pred = [nspredicate predicatewithformat:@"url contains '%@'", self.searchquery]; rlmresults<database *> *results = [database objectswithpredicate:pred];  if ([results count] == 0) {     nslog(@"results count == 0");     return nil; } 

now, when run this, 0 results. eventhough have 2 example entries have 'http://www.testingthis.com' url , search query 'testingthis'. ideas why i'm not getting results?

you need perform search query against restaurant class itself; not database. realm uses class specify determine table in apply query.

as aside, can inline nspredicate queries +[rlmobject objectswhere:], it's not necessary create separate nspredicate object (unless you've got specific reason). :)

rlmresults *restaurants = [restaurant objectswhere:@"url contains '%@'", @"testingthis"]; 

if you're trying query restaurant objects aren't in default realm, can alternatively use +[rlmobject objectsinrealm: where:] explicitly control database you're querying.


Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -