Reasons behind Cocoa's error code 512 = NSFileWriteUnknownError

We are developing a document-based Objective-C project, using NSPersistentDocument and NSPersistentStore to save a unique binary file on disk. No autosave.

Our application sometimes throws NSFileWriteUnknownError when trying to save the document, but the error description is obviously vague as this is an "unknown" error, not allowing us to debug easily.

Why would such an unknown error be ever raised? Why doesn't Core Data know why it cannot save a file?

We build using SDK 10.14 and run on macOS Monterey 12.3.1

Replies

Most Cocoa errors include underlying error information in the user info dictionary, typically in the NSUnderlyingErrorKey property. Do you see anything there?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

  • Hi @eskimo, thanks for the tip! The underlying error is "No known persistent store for URL", which surprises me since we can load and save the store to the same URL most of the time (on occasions where the error doesn't pop up)

Add a Comment