I have an NSArray that is extracted from core data. The entities in the array have a date attribute (of type NSDate ofcourse). What I want to do is this:
- The array needs to be displayed in a table view,
- the sections, and their titles are months , of the objects in the array
For example if I have 3 objects (april 1, april 3 & july 7) there should be 2 sections:
– april 2012(2 obj)
– july 2012 (1 obj)).
How do I split the array like this?
Try using a
NSFetchedResultsControllerand a customsectionNameKeyPathwhich should be a method in yourNSManagedObjectsubclass.The fetchedResultsController can be set up as following:
You need to implement the
monthAsStringmethod in your managedObject subclass. Allocate the NSDateFormatter only once, because it won’t perform well if you allocate a new instance for every call.