Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>So as it turns out the code above all works perfectly and there really is no error with how the sorting is working. The issue is obscured by my "day" function which is making UITableView sections based on the <code>NSDateFormatterFullStyle</code> representation of the the item's "date" property. However the reality is that the dates are all different when it comes to the time portion which explains why they were being sorted by the order they were created.</p> <p>I discovered this after trying Martin R's comment about using <code>sectionNameKeyPath:@"date"</code> and saw each row in its own section. </p> <p>Thus the solution to my issue is to only set the month, day, and year of the "date" property when it is set, this may be unique to my application since those are the only portions of the date that I care about, not the time.</p> <p>To do this I overrode the setter for "date" in my NSManagedObject "Item" with this code:</p> <pre><code>- (void)setDate:(NSDate *)date { NSDateComponents *components = [[NSCalendar currentCalendar] components:NSDayCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit fromDate:date]; NSInteger day = [components day]; NSInteger month = [components month]; NSInteger year = [components year]; NSDateComponents *comps = [[NSDateComponents alloc] init]; [comps setDay:day]; [comps setMonth:month]; [comps setYear:year]; NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; NSDate *newDate = [gregorian dateFromComponents:comps]; [self willChangeValueForKey:@"date"]; [self setPrimitiveValue:newDate forKey:@"date"]; [self didChangeValueForKey:@"date"]; }//end setDate </code></pre>
 

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