I have a TableViewController that I am using (datePicker) to add a date to the note with other Attributes. I am using CoreData and fetch to populate another TableViewController with the results. When it populates it shows up with the month: Dec 20, 2021, Feb 1, 2022, Feb 10, 2022, Feb 17, 2022, Feb 2, 2022, Jan 31, 2022, Jan 4, 2022 and so on ... How can I get it to sort correctly? Newest on top Feb 17, 2022 Feb 10, 2022 etc...
Thanks in advance.
let sortDescriptor = NSSortDescriptor(key: "date", ascending: true)
fetchRequest.sortDescriptors = [sortDescriptor]
hi,
you do not show the definition of your Core Data entity, nor the type of its attribute "date."
since the list of dates appears to be sorted alphabetically, i am guessing that you defined the date attribute in Core Data as a String (not as a Date) and that you are storing strings in what you call "date." that would explain the result above.
(BTW: to have Core Data sort by the Date type, you would want "ascending: false" for the NSSortDescriptor so that the most recent date comes out first.)
hope that helps,
DMG