ios - NSPredicate that uses @max with an other condition in a fetch request -
i have coredata entity song has date property pushdate , boolean property ispublic.
i need fetch latest public song.
to latest, can use -
request.predicate = [nspredicate predicatewithformat:@"pushdate==max(pushdate)"]; but when try -
request.predicate = [nspredicate predicatewithformat:@"pushdate==max(pushdate) , ispublic == yes"]; i don't result (i 100% sure have songs public == yes).
can use predicate ? if no why / correct way ?
thanks
you can try fetch objects public first.
nspredicate *predicate = [nspredicate predicatewithformat:@"ispublic == yes"]; [request setpredicate:predicate]; use sort descriptor sort pushdate:
nssortdescriptor *sortdesc = [nssortdescriptor sortdescriptorwithkey:@"pushdate" ascending:no]; [request setsortdescriptors:@[sortdesc]]; set limit of request one:
[request setfetchlimit:1];
Comments
Post a Comment