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.
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
Post a Comment