There is no template code in per se, but usually recommendations indicate that the user has an error message (most likely with UIAlertView
). Usually, saving the context fails when there are invalid objects (with excellent optional attributes), as well as one object that has two versions (this happens when the object is created in one context and is "updated" in another). In the first case, try to show the verification errors and give the user the opportunity to correct them on the same screen on which the save was performed. In the latter case, background merging methods are used, discussed in the CoreData cookie (which uses either deleting one of the object’s versions or merging changes).
Also from my experience, I would say that maintaining context in AppDelegate is not required. I suggest creating a separate context for creating the object and leaving the application delegate only to pass the initial MOC to the rootViewController
your window.
source share