Yimin Pang
Yimin Pang

Reputation: 35

When is NSDocumentController instance instantiated by default in a Document-Based template project?

I created a Document based Cocoa project in Xocode 8.0 on maxOS 10.11.6, using swift 3.0.1. I deleted the mainMenu.xib, document.xib, modified the infolist, and then added my own main function. Becasue I do not use Interface Builder at all.

In the Document.swift, I delete the windowNibFille variable, and override the makeWindowController() functiopnas follow:

override func makeWindowControllers() {
    let mainWindow = NSWindow(contentRect: NSMakeRect(0, 0, NSScreen.main()!.frame.width/2, NSScreen.main()!.frame.height/2), styleMask: [NSTitledWindowMask, NSResizableWindowMask, NSMiniaturizableWindowMask, NSClosableWindowMask], backing: NSBackingStoreType.buffered, defer: false)
    mainWindow.isOpaque = false
    mainWindow.center()
    mainWindow.isMovableByWindowBackground = true
    mainWindow.makeKeyAndOrderFront(nil)
    let mainWindowController = NSWindowController(window: mainWindow)
    addWindowController(mainWindowController)
}

I did not do anything else. If I build the project, I should not get menu, window, document running the compiled app, becuase I did not instantiate any NSDocumentController instance, nor NSDocuement nor NSWindow instances.

But he reality is that I ran the project, an window named untitled is shown. This is annoying, it seems that some invisiable code exists in an almost empty project. I want to do something before an untitled document is opened, how should I do it if a NSDocumentController instance is created out of my control?

Upvotes: 1

Views: 228

Answers (0)

Related Questions