Created
August 24, 2025 04:34
-
-
Save katagaki/61c8a70d46844f22178715feb1552f3f to your computer and use it in GitHub Desktop.
An empty AppKit app without using Storyboards
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 AppDelegate: NSObject, NSApplicationDelegate { | |
| var window: NSWindow! | |
| func applicationDidFinishLaunching(_ aNotification: Notification) { | |
| window = NSWindow( | |
| contentRect: NSRect(x: 0, y: 0, width: 800, height: 600), | |
| styleMask: [.titled, .closable], | |
| backing: .buffered, | |
| defer: false | |
| ) | |
| window.contentViewController = ViewController() | |
| window.makeKeyAndOrderFront(nil) | |
| } | |
| } |
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 AppKit | |
| let app = NSApplication.shared | |
| let delegate = AppDelegate() | |
| app.delegate = delegate | |
| _ = NSApplicationMain(CommandLine.argc, CommandLine.unsafeArgv) |
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 | |
| import SwiftUI | |
| class ViewController: NSViewController { | |
| override func viewDidLoad() { | |
| super.viewDidLoad() | |
| // If you are using SwiftUI: | |
| let viewController = NSHostingController(rootView: YourSwiftUIView()) | |
| self.view = viewController.view | |
| self.view.frame = .init(x: 0, y: 0, width: 800.0, height: 600.0) | |
| viewController.sceneBridgingOptions = .all | |
| // If not, you can use your own NSViewController | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment