4
votes

I am building a new document-based application in Swift for OS X using Xcode. I would like the default Document class to be called something that is not Document (in this case Notebook), though of course it would still subclass NSDocument (or NSPersistentDocument if I use Core Data). I can rename its file from Document.swift to Notebook.swift, but once I rename the actual class from Document to Notebook, running the application pops up the error alert "No document could be created." The console tells me "The DocumentType type doesn't map to any NSDocumentClass."

So, obviously I have to do other things to make the document architecture recognize my class once I have renamed it. But what? I found some directions on another site but they are old and written for Objective-C and XIB when I am using Swift and storyboards; what I need to do is likely to be quite different. What does one need to do to rename the main document class for a document-based application, in Swift, using storyboards?

EDIT: There was a request below for code. Basically, the default Document.swift or Notebook.swift file looks like

import Cocoa

class Document: NSDocument {
... [standard code for Document class goes here, edited out for brevity]
}

and I changed it to

import Cocoa

class Notebook: NSDocument {
[...]
}

It worked with the version on the top and does not work with the version on the bottom.

1
Hey there, do you have any code at all you can post to help out?KFDoom
Search your Xcode project for 'Document' (entire word, matching case).Willeke
Thank you, that worked. Will add a bit of detail below in case anyone else has the same problem.Displaced Hoser

1 Answers

8
votes

Willeke's suggestion above to search for "Document" (entire word, matching case) allowed me to find what I needed to do. For the record, I needed to go into Info.plist and go to Document types/Item 0(Document type)/Cocoa NSDocument Class , and change "$(PRODUCT_MODULE_NAME).Document" to "$(PRODUCT_MODULE_NAME).Notebook".