Skip to content

Instantly share code, notes, and snippets.

@florieger
Last active September 10, 2020 14:25
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save florieger/7ac5e7155f6faf18666f92f7d82f6cbc to your computer and use it in GitHub Desktop.
Save florieger/7ac5e7155f6faf18666f92f7d82f6cbc to your computer and use it in GitHub Desktop.
Swift AppDelegate without Storyboard / XIB for iOS.
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
var window: NSWindow?
func applicationDidFinishLaunching(_ aNotification: Notification) {
// Insert code here to initialize your application
mainWindowController = MainWindowController()
mainWindowController?.showWindow(self)
}
}
import Cocoa
class Application: NSApplication {
let strongDelegate = AppDelegate()
override init() {
super.init()
self.delegate = strongDelegate
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
...
<key>NSPrincipalClass</key>
<string>$(PRODUCT_MODULE_NAME).Application</string>
...
</dict>
</plist>
import Cocoa
class MainWindowController: NSWindowController {
init() {
let window = NSWindow(contentViewController: MyViewController())
super.init(window: window)
window.title = "My Window Title"
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
class MyViewController: NSViewController {
override func loadView() {
self.view = NSView()
self.view.frame = NSRect(x: 0, y: 0, width: 600, height: 400)
}
}
@florieger
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment