WWDC22 SALE: Save 50% on all my Swift books and bundles! >>

How to handle the Persistent Error for production app

Forums > iOS


[ My Question ]

In persistent.swift (or datacontroller as Paul usually named), there are many "fatalError," couldn't be remained in shipped app. But What is the correct way to handle them?

[ What I have known/ tried ]

I found https://developer.apple.com/documentation/coredata/nsmanagedobject/1535452-validation_error_codes so I can decode the error.

I have googled and search stack overflow for several days, but I do not get any concret information. One I have seen replied that there is no point to handle in production app, because if there is not enough space, apple will have been notify the user several times, and for other error, there is nothing a developer can do to recover. Some said it is important to notify the user if it doesn't save successfully.

[ My remaining question after above efforts ]

However, I do not know what to do with those error...

For example, assuming the user fails to context.save()

Firstly, I don't know which error might occur under which command, and even I try to pick those I think most likely happened as below:

NSMigrationManagerDestinationStoreError, NSMigrationManagerSourceStoreError, NSPersistentStoreIncompleteSaveError, or NSPersistentStoreSaveError....

I don't know what I should do after knowing the error source.

Tell user there is a save error ask him to try again later? Try to save again silently?

If there is a merge error, what could i do?

If they don't find model in store, what could I do? If i create a new one, then it won't be the same as previous one.......

I see many of you have release in appconnect, It would be so nice if you like to share your experience?

Thank you very much!


Save 50% in my Black Friday sale.

SAVE 50% To celebrate WWDC22, all our books and bundles are half price, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.

Save 50% on all our books and bundles!

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

Unknown user

You are not logged in

Log in or create account

Link copied to your pasteboard.