For a simple, resourceless cocoa apps I used to manually setup the application lifecycle (mimicking what's documented here: https://aninterestingwebsite.com/documentation/appkit/nsapplication), so my main.swift would look like:
import Cocoa
let delegate = SomeDelegate()
_ = NSApplication.shared
NSApp.delegate = delegate
NSApp.run()
This triggers a warning in Xcode 26.2: "Main actor-isolated conformance of SomeDelegate cannot be used in nonisolated context; this is an error in Swift 6 language mode".
so what is the recommended way to refactor above so that it is Swift 6 compliant?
I got this working as following:
- Using Xcode 26.4, I created a new project from the macOS > App template, choosing Storyboard for the UI.
- I removed
@mainfromAppDelegate. - I added a
main.swiftfile like so:
import Cocoa
func main() {
let delegate = AppDelegate()
_ = NSApplication.shared
NSApp.delegate = delegate
NSApp.run()
}
main()
The difference is that I put the code into a main() function. That function name isn’t special — you could just as easily call it foo() — but it’s important that the code not be at the top level. Top-level code is weird in Swift (-:
Having said that, I recommend against doing this. Rather, just call NSApplicationMain. Note that the doc you referenced says “which is functionally similar to”, not “is implement as”. The actual implementation of NSApplicationMain is very different, and by not calling it you’re taking yourself far off the beaten path.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"