A lightweight Swift framework for creating macOS preferences windows with SwiftUI content in AppKit-based applications.
| App Architecture | Recommended Approach |
|---|---|
AppKit (NSApplicationDelegate) |
✅ Use SettingsKit |
SwiftUI (@main struct App) |
Use native Settings scene |
Note: If your app uses the SwiftUI App lifecycle (
@main struct MyApp: App), you should use SwiftUI's built-inSettingsscene instead of this library.
- Native macOS toolbar-style tab interface
- SwiftUI content support with AppKit integration
- Automatic window resizing when switching tabs
- Accessibility support (respects Reduce Motion setting)
- Simple, protocol-based API
- macOS 14.0+
- Swift 5.9+
- Xcode 15.0+
Add the following to your Package.swift:
dependencies: [
.package(url: "https://github.com/LZhenHong/SettingsKit.git", from: "0.0.2")
]Or add it through Xcode:
- File → Add Package Dependencies...
- Enter the repository URL
- Select the version rule and add to your target
Conform to the SettingsPane protocol to create your setting panes:
import SettingsKit
import SwiftUI
struct GeneralSettingPane: SettingsPane {
var tabViewImage: NSImage? {
NSImage(systemSymbolName: "gear", accessibilityDescription: "General")
}
var preferredTitle: String { "General" }
var view: some View {
Form {
Toggle("Launch at login", isOn: $launchAtLogin)
Toggle("Show in menu bar", isOn: $showInMenuBar)
}
.formStyle(.grouped)
.frame(width: 400, height: 200)
}
}import SettingsKit
class AppDelegate: NSObject, NSApplicationDelegate {
private var settingsWindowController: SettingsWindowController?
func applicationDidFinishLaunching(_ notification: Notification) {
let panes: [any SettingsPane] = [
GeneralSettingPane(),
AboutSettingPane(),
]
settingsWindowController = SettingsWindowController(panes: panes, title: "Preferences")
}
@IBAction func showPreferences(_ sender: Any) {
settingsWindowController?.show()
}
@IBAction func showAboutPane(_ sender: Any) {
// Show window and select the second pane directly
settingsWindowController?.show(paneIndex: 1)
}
}struct AdvancedSettingPane: SettingsPane {
var isEnabled: Bool {
// Only show this pane for power users
UserDefaults.standard.bool(forKey: "showAdvancedSettings")
}
// ... rest of implementation
}A protocol that defines the content and appearance of a settings pane.
| Property | Type | Description |
|---|---|---|
tabViewImage |
NSImage? |
The image displayed in the toolbar |
preferredTitle |
String |
The title displayed in the toolbar and window title |
isEnabled |
Bool |
Whether this pane should be displayed (default: true) |
view |
some View |
The SwiftUI view content |
A window controller that presents a macOS-style preferences window.
| Property | Type | Description |
|---|---|---|
panes |
[any SettingsPane] |
The setting panes managed by this controller |
selectedPaneIndex |
Int |
The index of the currently selected pane |
| Method | Description |
|---|---|
init(panes:title:) |
Creates a new settings window with the given panes |
show(paneIndex:level:) |
Shows the settings window, optionally selecting a specific pane |
selectPane(at:) |
Selects the pane at the specified index |
This project is licensed under the MIT License - see the LICENSE file for details.