2

I have a CoreData model and I can insert some string as a new row. And then my NSFetchedResultsController type return .Insert.

But when I change my data like:

let uri = NSURL(string: "My Object ID")!
let mID = self.managedObjectContext!.persistentStoreCoordinator!.managedObjectIDForURIRepresentation(uri)
let oldM = try self.managedObjectContext!.existingObjectWithID(mID!) as! Soft
oldM.info = "New data"

Sometimes NSFetchedResultsController does not send .Update but sometimes it works well. What is the reason? Is any way to make a forced update to NSFetchedResultsController?

UPDATE I tried check when this code is call

func controllerWillChangeContent(controller: NSFetchedResultsController) {
    print("test 1")
}

func controllerDidChangeContent(controller: NSFetchedResultsController) {
    print("test 2")
}

and this both value i have only when NSFetchedResultsController send some type .Update .Insert so i don't even update tableView, maybe i can add observe and then update my row.

Wraith
  • 504
  • 6
  • 28
  • Have a look at http://stackoverflow.com/a/16296365/1187415, that *might* be a possible solution to your problem. – Martin R Sep 20 '15 at 08:28

1 Answers1

0

Probably some operations you handle with this code do not update table data. You usually need to call tableView.reloadData() to get updates on screen.

Mike K
  • 961
  • 8
  • 15
  • With a fetched results controller you usually do *not* have to call reloadData, because after changes of the managed objects the affected table view rows are updated automatically. – Martin R Sep 20 '15 at 07:14
  • Row are updated upon calling didChangeObject, where you call methods appropriate to changeType to reload the data. And if the operation called is not one of .Insert, .Update, etc.. It is a common practice to call .reloadData(). Am I wrong? – Mike K Sep 20 '15 at 08:14
  • "updated automatically" was badly worded. Usually you call insertRowsAtIndexPaths/deleteRowsAtIndexPaths/reloadRowsAtIndexPaths, see for example the sample code in https://developer.apple.com/library/prerelease/ios/documentation/CoreData/Reference/NSFetchedResultsControllerDelegate_Protocol/index.html, so that you get nicely animated updates. – Martin R Sep 20 '15 at 08:18