ios - How to perform a query by field using a predicate? -


i can't seem figure out how write nspredicate filter query search field. i'm trying search field titled "location" , search string in field , see if string "ca" matches users string "currentstate" (which ca in case, "currentstate" users location (placemark.administrativearea) assigned in string) , retrieve records match filters.

enter image description here

here's code i'm trying use:

func retrievestatemoods(lateststatemood:string) {       // create query     let predicate:nspredicate = nspredicate(format: "location", "\(self.currentstate)%k") // crashes here!!     let sort:nssortdescriptor = nssortdescriptor(key: "creationdate", ascending: false)     let query:ckquery = ckquery(recordtype: "state", predicate: predicate)     query.sortdescriptors = [sort] 

etc...

it crashes when try create predicate. here's error code:

terminating app due uncaught exception 'nsinvalidargumentexception', reason: 'unable parse format string "location"' first throw call stack:

i know i'm not far off can't figure out how format predicate properly. tried reading nspredicate example in developer reference it's in objective-c.

this should be:

nspredicate(format: "location == %@", self.currentstate) 

Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -