Answer the question
In order to leave comments, you need to log in
Why, when adding multiple CoreData objects to the main context, do they arrive at the NSFetchedResultController out of order?
When adding multiple CoreData objects to the main context, they arrive at the NSFetchedResultController out of order. As a result, an error occurs when animating the addition / deletion of rows in the NSTableView table.
for i in 0...10 {
let note1 = Note(entity: self.entityDescription, insertInto: context)
note1.modificationTime = Date()
note1.text = "note = \(i)"
note1.bookmarked = true
note1.uniqueID = UUID().uuidString
}
Class NoteListViewController
- count of object = Optional(11)
- insert object = Optional("note = 9") at IndexPath = Optional([0, 1])
Class NoteListViewController
- count of object = Optional(11)
- insert object = Optional("note = 7") at IndexPath = Optional([0, 3])
Class NoteListViewController
- count of object = Optional(11)
- insert object = Optional("note = 8") at IndexPath = Optional([0, 2])
Class NoteListViewController
- count of object = Optional(11)
- insert object = Optional("note = 5") at IndexPath = Optional([0, 5])
Class NoteListViewController
- count of object = Optional(11)
- insert object = Optional("note = 6") at IndexPath = Optional([0, 4])
Class NoteListViewController
- count of object = Optional(11)
- insert object = Optional("note = 3") at IndexPath = Optional([0, 7])
Class NoteListViewController
- count of object = Optional(11)
- insert object = Optional("note = 2") at IndexPath = Optional([0, 8])
Class NoteListViewController
- count of object = Optional(11)
- insert object = Optional("note = 4") at IndexPath = Optional([0, 6])
Class NoteListViewController
- count of object = Optional(11)
- insert object = Optional("note = 10") at IndexPath = Optional([0, 0])
Class NoteListViewController
- count of object = Optional(11)
- insert object = Optional("note = 1") at IndexPath = Optional([0, 9])
Class NoteListViewController
- count of object = Optional(11)
- insert object = Optional("note = 0") at IndexPath = Optional([0, 10])
class NOTES_LIST_VIEW_CONTROLLER -> func controllerDidChangeContent()
Answer the question
In order to leave comments, you need to log in
you can not do save Context after each addition, add all objects and then save the context. I hope you are properly adding and changing not in MOC ( mainQueueConcurrencyType ), but in privateQueueConcurrencyType , which is a child of MOC.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question