Note that there are some explanatory texts on larger screens.

plurals
  1. PONSPredicate filtering with NSManagedObject's helper method
    primarykey
    data
    text
    <p>I have a UITable view which contains a list of NSManagedObjects called Assignment. I am using NSPredicate to filter the list. I am filtering assignments that should be shown for today and yesterday for a player:</p> <pre><code>NSPredicate *predicate = [NSPredicate predicateWithFormat: @"player == %@ AND (day == %@ OR day == %@)", player, [NSNumber numberWithInt:[self todaysDayNumber]], [NSNumber numberWithInt:[self yesterdaysDayNumber]]]; </code></pre> <p>I need to add an additional level of filtering. I want to filter out assignments that should only be shown biweekly. So I added this methods to Assigment: </p> <pre><code>-(BOOL)thisWeeks{ //If this is a weekly assigment if ([self.weekly boolValue]) { return YES; } //Determine the week number NSCalendar *calendar = [NSCalendar currentCalendar]; NSUInteger unitFlags = NSWeekCalendarUnit; NSDateComponents *dateComponents = [calendar components:unitFlags fromDate:[NSDate date]]; NSUInteger week = [dateComponents week]; //Assigned week even? if ([self.weekNumber intValue] % 2){ //Current week even? if (week % 2) { return YES; } } //Assigned week odd? if (!week % 2) { //Current week odd? if (![self.weekNumber intValue] % 2){ return YES; } } //Should not be shown this week. return NO; } </code></pre> <p>is it possible to use this helper method "thisWeeks" as a filter in NSPredicate?</p> <p>If I'm "doing it wrong", I could manually filter the fetched results, but I am unsure as to how I would put the results back into NSFetchedResultsController such that my UITable view could continue using NSFetchedResultsController.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload