I currently am using CoreData for local storage of my model. I have successfully implemented an NSfetchedResultsController to manage the retrieval and presentation of the data in a tableView.
I wish the data to be organized in sections by local day. So each section will be a unique local day. Similar to most chat apps.
I know that I can save a date property in my managedObject in addition to the timestamp and use that as the sectionNameKeyPath, however that will not work when the user changes the timezone on their device. In this case I will have to go back and change every entry in coreData and change the local day entry.
Is there a simpler way to achieve organizing by day taking into account the possibility of the time zone changing?
let request = NSFetchRequest<NSFetchRequestResult>(entityName: "Blog")
let blogSort = NSSortDescriptor(key: "dateCreated", ascending: true)
request.sortDescriptors = [blogSort]
fetchedResultsController = NSFetchedResultsController(fetchRequest: request, managedObjectContext: context, sectionNameKeyPath: "localDate", cacheName: nil)
In this example, dateCreated is a timestamp for the date the blog was created and localDate is the actual calendar date.