My team and I have been working on an existing, non-document-based Cocoa application. This is our first Cocoa app, although we\'ve done a number of iOS apps thus far.
Th
An often found suggestion is to create a new document based application and move all you existing code in there. This can be cumbersome for a large workspace with all kinds of stuff nicely configured. Let alone breaking version control.
I took the following simple steps and it worked:
from this this generated project, copy the following section from the Info.plist (open the file with a normal text-editor):
CFBundleDocumentTypes
CFBundleTypeExtensions
mydoc
CFBundleTypeIconFile
CFBundleTypeName
DocumentType
CFBundleTypeOSTypes
????
CFBundleTypeRole
Editor
NSDocumentClass
$(PRODUCT_MODULE_NAME).Document
and paste it in the Info.plist file in your own project.
Copy Document.swift from the generated document-based project into your own project.
it contains a method:
override func makeWindowControllers() {
// Returns the Storyboard that contains your Document window.
let storyboard = NSStoryboard(name: "Main", bundle: nil)
let windowController = storyboard.instantiateController(withIdentifier: "Document Window Controller") as! NSWindowController
self.addWindowController(windowController)
}
It creates a new window just the way you application normally would. If you storyboard has only one windowcontroller the 'withIDentifier'-field can contain something arbitrary. If you have more window controllers in your storyboard, the identifier needs to correspond to the right windowcontroller for new documents.