纯代码创建 macOS 应用
默认情况下使用 Xcode 创建的 macOS APP 是基于 storyboard 的,对于多人协作的项目,使用纯代码创建界面比 storyboard 更方便。
首先删掉 storyboard 和相关的设置
删除 Main.storyboard 和 Info.plist 里的 Main storyboard file base name 项目:

完成以后,再运行项目会发现此时 applicationDidFinishLaunching 不会被系统调用了,这是因为 AppDelegate 没有创建实例导致的。
创建一个 main.swift ,作用类似与 Objective-C 的项目里的 main.m。
import Cocoa
fileprivate let appDelegate = AppDelegate()
NSApplication.shared.delegate = appDelegate
fileprivate let argc = CommandLine.argc
fileprivate let argv = CommandLine.unsafeArgv
_ = NSApplicationMain(argc, argv)
最后移除 AppDelegate.swift 里的 @NSApplicationMain 标识,否则编译会产生符号重复的错误。
纯代码创建 iOS 应用
和 macOS 的方法差不多,移除 AppDelegate.swift 里的 @UIApplicationMain 然后新建 main.swift:
import UIKit
fileprivate let argc = CommandLine.argc
fileprivate let argv = CommandLine.unsafeArgv
UIApplicationMain(argc, argv, nil, NSStringFromClass(AppDelegate.self))
Info.plist 里需要移除的以下几处包含 Main storyboard 配置的地方:

