My app maintains Folder
objects (an NSManagedObject
subclass). Each folder may have subfolders
of the same class (an ordered to-many relationship, the reciprocal relationship is called parent
). Folders also have a name
attribute (NSString
).
These folders show in an NSOutlineView
and can be rearranged by the user. Their managedObjectContext
is the “view context” of the application (using the main queue). Each Folder
shown in the outline view is the objectValue
of a table cell view, and is therefore retained so long as the table cell view is alive.
Problem: when a subfolder is added/removed to/from a parent folder, for instance via insertObject:inSubfoldersAtIndex:
sent to the parent folder, the other subfolders are often turned into faults when the parent folder is saved (which happens when the context is saved), even though they still show in the outline view. Therefore their names disappear.
I have no idea why code data sees fit to turn these subfolders into faults in this situation. It doesn’t do it consistently and never does it when the names of folders are changed (which also requires a save). Note: the folder that was inserted into a parent is never turned into a fault. Only other subfolders of the same parent are.
My current solution to this issue is to reload items from the outline view after every save, which fires faults and prevents folder names from disappearing, but I’d rather prevent the folders from turning into faults in the first place.
How can I do that?