- Delete the
MainMenu.xib
orStoryboard.main
files. - Respectively, delete the
NSMainNibFile
orNSMainStoryboardFile
keys in the project’sInfo.plist
. - Add a
-NSConstraintBasedLayoutVisualizeMutuallyExclusiveConstraints YES
launch argument. - Remove the
@main
attribute from theAppDelegate
class. - Create a
main.swift
file, and add the code snippet below. Aside from bootstrapping the app, it checks whether the app is run within Xcode’s test environment. If so, the standardAppDelegate
isn’t initialized. This speeds up the unit tests significantly (see this and this).
import Cocoa
let app = NSApplication.shared
if NSClassFromString("XCTestCase") != nil {
app.run()
} else {
let appDelegate = AppDelegate()
app.delegate = appDelegate
_ = NSApplicationMain(CommandLine.argc, CommandLine.unsafeArgv)
}
- Create a menu bar (an instance of
NSMenu
) and assign it to themainMenu
property of the sharedNSApplication
instance.