SwiftWindowLauncher is an easy way to open any window from the CLI or main function. It is also designed to integrate seamlessly with SwiftUI and AppKit.
The following environment is required to use this library.
This package includes four executable targets that demonstrate every combination of entry point and UI framework. Each one opens a tab-based window (SwiftUI TabView / AppKit NSTabViewController) and keeps running its own work after the window is on screen.
| Target | Entry point | UI framework |
|---|---|---|
MainFunc-SwiftUI-Example |
static func main() |
SwiftUI |
MainFunc-AppKit-Example |
static func main() |
AppKit |
CLI-SwiftUI-Example |
swift-argument-parser command |
SwiftUI |
CLI-AppKit-Example |
swift-argument-parser command |
AppKit |
swift run MainFunc-SwiftUI-ExampleBy using this package, you can open any window during CLI or main function execution.
Pass any SwiftUI view to launch. In an async context, launch returns once the content is actually on screen, so your code can keep running while the window stays open. The process terminates after every window has been closed.
import SwiftUI
import WindowLauncher
struct ContentView: View {
var body: some View {
Text("Hello, Swift Window Launcher!")
}
}
@main
struct MyApp {
static func main() async throws {
await WindowLauncher.shared.launch {
ContentView()
}
// The window is now visible — you can keep working here.
print("Still running after the window opened!")
}
}Each subsequent launch call opens an additional window. The content is presented through a real SwiftUI WindowGroup scene, so native window chrome — such as the toolbar-integrated tab bar of a TabView and navigationTitle handling — works as in a regular SwiftUI app.
You can also pass an NSViewController or NSView. The window is created with NSWindow(contentViewController:), so controller-driven window features — NSToolbar customization, NSTabViewController with tabStyle = .toolbar, and so on — integrate with the window the same way they do in a regular AppKit app.
import AppKit
import WindowLauncher
await WindowLauncher.shared.launch(
MyViewController(),
title: "Swift Window Launcher"
)Calling launch from a non-async context starts the application's main run loop on the spot and never returns. Use this form when opening the window is the last thing your program does.
WindowLauncher.shared.launch {
ContentView()
}
// Never reached.Add the following files to the Package.swift file for use. For more information, please visit swift.org.
dependencies: [
// Add this code
.package(url: "https://github.com/KC-2001MS/SwiftWindowLauncher.git", from: "0.0.1"),
],Swift-DocC is currently being implemented. Documentation
See CONTRIBUTING.md if you want to make a contribution.
If you would like to make a donation to this project, please click here. The money you give will be used to improve my programming skills and maintain the application.

Pay by PayPal