objective c - NSPredicate by creationDate, only get first result -
i trying figure out way use nspredicate (i think tool need use) use cloudkit query recent ckrecord of record type.
because recent one, don't need of ckrecords returned me, nor want set limited span of time (as app may have bunch of people using @ times, , have close 0 people using it). closest post find towards question involved getting ckrecords between 2 dates (a few minutes ago, , when query started).
this way, if person recent record , 2 months old, or 2 seconds old, query work.
anyone know how this? i've got code working using predicate finds records, part needs fixing. here's partial code of segment working on now:
nspredicate *thepredicate = [nspredicate predicatewithformat:@"truepredicate"]; ckquery *query = [[ckquery alloc] initwithrecordtype:@"photo" predicate:thepredicate]; [[[ckcontainer defaultcontainer] publicclouddatabase] performquery:query inzonewithid:nil completionhandler:^(nsarray *results, nserror *error) { }];
you solve using ckqueryoperation set resultslimit 1. query can use truepredicate. on query add nssortdiscriptor key creationdate , ascending false sortdescriptors array. way result 1 record inserted recently. if record older 2 months.
Comments
Post a Comment