Thanks for the info... I've double checked and we're def displaying non-saved core data in the UITableView.
fileprivate let managedObjectContext = (UIApplication.shared.delegate as! AppDelegate).managedObjectContext /
lazy var fetchedResultsController: NSFetchedResultsController = { () -> NSFetchedResultsController<NSFetchRequestResult> in
let fetchRequest = NSFetchRequest<NSFetchRequestResult>(entityName: "Connection")
fetchRequest.includesPendingChanges = false
let sortDescriptor = NSSortDescriptor(key: "indexPathRow", ascending: true)
fetchRequest.sortDescriptors = [sortDescriptor]
let fetchedResultsController = NSFetchedResultsController(fetchRequest: fetchRequest, managedObjectContext: self.managedObjectContext, sectionNameKeyPath: nil, cacheName: nil)
fetchedResultsController.delegate = self
return fetchedResultsController
}()
These are the properties I'm using for my NSFetchedResultsController. The performFetch happens in viewDidLoad and these are my delegate methods
func controllerWillChangeContent(_ controller: NSFetchedResultsController<NSFetchRequestResult>) {tableView.beginUpdates()}
func controllerDidChangeContent(_ controller: NSFetchedResultsController<NSFetchRequestResult>) {tableView.endUpdates()}
func controller(_ controller: NSFetchedResultsController<NSFetchRequestResult>, didChange sectionInfo: NSFetchedResultsSectionInfo, atSectionIndex sectionIndex: Int, for type: NSFetchedResultsChangeType) {}
func controller(_ controller: NSFetchedResultsController<NSFetchRequestResult>, sectionIndexTitleForSectionName sectionName: String) -> String? {return ""}
func controller(_ controller: NSFetchedResultsController<NSFetchRequestResult>, didChange anObject: Any, at indexPath: IndexPath?, for type: NSFetchedResultsChangeType, newIndexPath: IndexPath?) {
switch (type) {
case .insert: if var indexPath = newIndexPath {
indexPath.section = indexPath.section + 1
tableView.insertRows(at: [indexPath], with: .fade)
}
case .delete: if var indexPath = indexPath {
indexPath.section = indexPath.section + 1
tableView.deleteRows(at: [indexPath], with: .fade)
}
case .update: if var indexPath = indexPath {
indexPath.section = indexPath.section + 1
tableView.reloadRows(at: [indexPath], with: .none)
}
case .move:
if var indexPath = indexPath {
indexPath.section = indexPath.section + 1
tableView.deleteRows(at: [indexPath], with: .fade)
}
if var newIndexPath = newIndexPath {
newIndexPath.section = newIndexPath.section + 1
tableView.insertRows(at: [newIndexPath], with: .fade)
}
}
}