Core Data - why was this returned ?

4 views
Skip to first unread message

Jonathan

unread,
Jan 28, 2016, 10:27:33 AM1/28/16
to iphone google group
Hello,

In the latest version of my music player, I'm doing a lookup on Tracks with this predicate

 NSPredicate *predicate = [NSPredicate predicateWithFormat:@"NOT (ANY genreRel.status_date <= status_date)"];


Checking the returned data with 
    

for (Track *trk in fetchController.fetchedObjects){

   for(Genre *gen in trk.genreRel){

      if([trk.status_date timeIntervalSinceNow] >= [gen.status_date timeIntervalSinceNow]){

         NSLog(@"Should not have been returned. track date %@, genre date %@ %@", trk.status_date, gen.status_date);

      }

   }

}


Ended up with over a thousand of messages like this. 


016-01-28 09:44:58.040 FMA Player[323:15902] Should not have been returned. track date 2016-01-28 14:36:12 +0000 genre date 2015-10-20 21:16:47 +0000 


Is there a flaw in my predicate?  Or a bug in the Core Data process?  Any suggestions for a predicate that will do this reliably? 


Thanks,

Jonathan 



Jesse Tayler

unread,
Jan 28, 2016, 10:40:17 AM1/28/16
to iphonesdkd...@googlegroups.com
why do you have the ANY in there when there’s only one argument being run?

by the look of it, you might just want to say "genreRel.status_date <= status_date” ?

not that I understand what’s wrong, but you can easily test a predicate using an array in a sandbox or debugger which might help you get the exact predicate format you need.
> --
> You received this message because you are subscribed to the Google Groups "iPhone SDK Development" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to iphonesdkdevelop...@googlegroups.com.
> To post to this group, send email to iphonesdkd...@googlegroups.com.
> Visit this group at https://groups.google.com/group/iphonesdkdevelopment.
> For more options, visit https://groups.google.com/d/optout.

jonathan.nyc

unread,
Jan 28, 2016, 12:40:16 PM1/28/16
to iPhone SDK Development
genreRel.status_date represents all the dates in the related set, not just one value.  The predicate would be correctly rejected 
without the ANY.  


On Thursday, January 28, 2016 at 10:40:17 AM UTC-5, jtayler wrote:
why do you have the ANY in there when there’s only one argument being run?

by the look of it, you might just want to say "genreRel.status_date <= status_date” ?

not that I understand what’s wrong, but you can easily test a predicate using an array in a sandbox or debugger which might help you get the exact predicate format you need.



> On Jan 28, 2016, at 10:27 AM, Jonathan <jonath...@gmail.com> wrote:
>
> Hello,
>
> In the latest version of my music player, I'm doing a lookup on Tracks with this predicate
>
>  NSPredicate *predicate = [NSPredicate predicateWithFormat:@"NOT (ANY genreRel.status_date <= status_date)"];
>
> Checking the returned data with
>    
> for (Track *trk in fetchController.fetchedObjects){
>    for(Genre *gen in trk.genreRel){
>       if([trk.status_date timeIntervalSinceNow] >= [gen.status_date timeIntervalSinceNow]){
>          NSLog(@"Should not have been returned. track date %@, genre date %@ %@", trk.status_date, gen.status_date);
>       }
>    }
> }
>
> Ended up with over a thousand of messages like this.
>
> 016-01-28 09:44:58.040 FMA Player[323:15902] Should not have been returned. track date 2016-01-28 14:36:12 +0000 genre date 2015-10-20 21:16:47 +0000
>
> Is there a flaw in my predicate?  Or a bug in the Core Data process?  Any suggestions for a predicate that will do this reliably?
>
> Thanks,
> Jonathan
>
>
>
> --
> You received this message because you are subscribed to the Google Groups "iPhone SDK Development" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to iphonesdkdevelopment+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages