344 days ago · Tech · 0 comments

Now that we actually have a proper Mac app up and running, let’s delve into making a user interface! Making a window First, we’ll need a window. We want this window to open on startup, so let’s implement the applicationDidFinishLaunching(_:) app delegate method: // main.swift import AppKit let _ = NSApplication.shared let appDelegate = AppDelegate() NSApp.delegate = appDelegate NSApp.run() class AppDelegate: NSObject, NSApplicationDelegate { var window: NSWindow! = nil func applicationDidFinishLaunching(_ notification: Notification) { window = NSWindow( contentRect: .init(x: 0, y: 0, width: 200, height: 100), styleMask: [.titled, .closable, .miniaturizable, .resizable], backing: .buffered, defer: true, ) window.makeKeyAndOrderFront(nil) } } That might look a bit intimidating at first, but I promise it isn’t that bad! contentRect specifies the position and size of the window’s content area on the display, styleMask lets us say that the window has all the usual behaviors, and the other…

No comments yet. Log in to reply on the Fediverse. Comments will appear here.