I am attempting to format my sectionNameKeyPath
for my core data fetch using a stored NSDate
attribute. It is fully working and pulling/sorting the records into sections based on the NSDate
but I am not sure how to format it to display it by dd-mm-yyyy.
I know how to format NSDate
using:
let date = NSDate(timeIntervalSince1970:myTimeInterval)
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "dd-MM-yyyy"
My current fetch request using core data attribute sectionDate
as the section division for sectionNameKeyPath
FETCH
let fetchRequest = NSFetchRequest(entityName: "VisitDetails")
let primarySortDescriptor = NSSortDescriptor(key: "dateDue", ascending: false)
let sortDescriptors = [primarySortDescriptor]
fetchRequest.sortDescriptors = sortDescriptors
let frc = NSFetchedResultsController(
fetchRequest: fetchRequest,
managedObjectContext: self.managedObjectContext!,
sectionNameKeyPath: "dateSections",
cacheName: nil)
frc.delegate = self
So to clarify I am wanting to format the output and sort by just the dd-MM-yyy. Currently, it is looking like:
I presume a Hack is creating an additional attribute and inputting a formatted string then using this to section the results?