Creating a Cocoa application without NIB files

前端 未结 11 736
余生分开走
余生分开走 2020-12-04 10:24

Yes, I know this goes against the whole MVC principle!

However, I\'m just trying to whip up a pretty trivial application - and I\'ve pretty much implemented it. Howe

11条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-04 10:30

    The sample swift code for the autoreleasepool snippet provided above does not work in modern Xcode. Instead, you need to get rid of the @NSApplicationMain in your App Delegate source file, if there is one (Xcode now adds these for new projects), and add a main.swift file that contains the following:

    The top level code sample above no longer works in recent versions of Xcode. Instead use this:

    import Cocoa
    
    let delegate = ExampleApplicationController() //alloc main app's delegate class
    NSApplication.shared().delegate = delegate //set as app's delegate
    
    let ret = NSApplicationMain(CommandLine.argc, CommandLine.unsafeArgv)
    

提交回复
热议问题