I'm just starting to learn coredata. In my core data model I have a date stamp (of type NSDate) which includes the date and time (I need this information). Now I would like to organize the Core Data table into sections by days. How can I do this. The only samples I found directly use a core data entity to create the sections, in this case this gives me a section for every entry in the table. Any help would be very welcome, especially with a code sample.
views:
1249answers:
1Add a method to your managed object class that returns the title for the section an object should be in.
For example, if you have a class of Thingummy
that includes an NSDate
and you want them grouped by day, add a method to to your Thingummy
class that looks at the NSDate
and returns a string with the day.
Then, when firing up your NSFetchedResultsController
give it the name of that method as its sectionNameKeyPath
.
(See this post in the Apple iPhone Dev Forums (if you're registered there): https://devforums.apple.com/message/81710#81710)
There are a couple of approaches to getting the code into your managed object class. If you just add it, you'll need to watch how Xcode generates your code for you. If you get it to regenerate the code straight to the file in the future then it will overwrite your custom class.
Either get it to put the code in the clipboard, or you can add your custom method to the managed object class as a category in a separate file, where it will be safe from automated tampering.