Last active
September 10, 2020 14:25
-
-
Save florieger/7ac5e7155f6faf18666f92f7d82f6cbc to your computer and use it in GitHub Desktop.
Swift AppDelegate without Storyboard / XIB for iOS.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@NSApplicationMain | |
class AppDelegate: NSObject, NSApplicationDelegate { | |
var window: NSWindow? | |
func applicationDidFinishLaunching(_ aNotification: Notification) { | |
// Insert code here to initialize your application | |
mainWindowController = MainWindowController() | |
mainWindowController?.showWindow(self) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Additional information can be found at https://stackoverflow.com/questions/40008141/nsapplicationdelegate-not-working-without-storyboard