Core data subquery predicate

后端 未结 1 1841
野趣味
野趣味 2020-12-20 09:21

I\'m trying to get a subquery predicate to work and I\'m struggling.

I have two entities.

[League] <---->> [Game]

Game has a property kickOf

相关标签:
1条回答
  • 2020-12-20 09:51

    Have you tried (untested):

    [NSPredicate predicateWithFormat:@"SUBQUERY(games, $g, $g.kickOffDate >= %@ AND $g.kickOffDate <= %@).@count > 0", [self startOfDay:[NSDate date]],[self endOfDay:[NSDate date]]];
    

    == League that have a game with a kick-off date in a given range

    Your solution is equivalent to:

    [NSPredicate predicateWithFormat:@"ANY games.kickOffDate >= %@ AND ANY games.kickOffDate <= %@",start,end];
    

    == League that have a game that start after a given date and have a game that start before a given date (could be different games, or the same game)

    Which should return more results than you like.

    Edit:
    As @Martin R suggested, you should verify that your data does indeed include a League answering the predicate to test it.
    If you still get no results, check to see if there were errors during execution of the request and your data-stack is properly initialized.

    0 讨论(0)
提交回复
热议问题