UIDocument no longer saving, error in URLByAppendingPathExtension

I've been working on an iOS app with UIDocuments. They were saving fine. Now all of a sudden, after unrelated changes, nothing will save.

Here is the error printed in Xcode console:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSURL URLByAppendingPathExtension:]: component, components, or pathExtension cannot be nil.'

log.debug("save to:\(self.document.fileURL)")
document.save(to: document.fileURL, for: .forOverwriting) { success in
    ...
}

The log message there prints a valid URL.

Accepted Reply

Due to some problem with git, I'd lost the Info.plist definitions of the "Document Types" and "Exported Type Identifiers". Once I added those back, this error disappeared.

Replies

Due to some problem with git, I'd lost the Info.plist definitions of the "Document Types" and "Exported Type Identifiers". Once I added those back, this error disappeared.

I ran into the same error after updating to Xcode 13.3, however I never haver had a relevant "Document Types" or "Exported Type Identifiers" for my UIDocument. I found I was able to get around the problem by overriding "fileType" and "savingFileType". I'm not sure what is making use of these values as the document filename appears to be the same.