Skip to content

Instantly share code, notes, and snippets.

@katagaki
Created August 24, 2025 04:34
Show Gist options
  • Select an option

  • Save katagaki/61c8a70d46844f22178715feb1552f3f to your computer and use it in GitHub Desktop.

Select an option

Save katagaki/61c8a70d46844f22178715feb1552f3f to your computer and use it in GitHub Desktop.
An empty AppKit app without using Storyboards
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)
}
}
import AppKit
let app = NSApplication.shared
let delegate = AppDelegate()
app.delegate = delegate
_ = NSApplicationMain(CommandLine.argc, CommandLine.unsafeArgv)
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