SettingsKit makes it easier to add a settings window to a SwiftUI app for macOS.
Name | Description |
---|---|
Settings | A scene modifier for adding a settings window. |
Settings Image Button Style | The button style of an image picker in the settings. |
Settings Action | Contains a function for showing the settings window manually and another function for getting the active settings tab and subtabs selection. |
- Open your Swift package in Xcode.
- Navigate to
File > Add Packages
. - Paste this URL into the search field:
https://github.com/david-swift/SettingsKit-macOS
- Click on
Copy Dependency
. - Navigate to the
Package.swift
file. - In the
Package
initializer, underdependencies
, paste the dependency into the array.
- Open your Xcode project in Xcode.
- Navigate to
File > Add Packages
. - Paste this URL into the search field:
https://github.com/david-swift/SettingsKit-macOS
- Click on
Add Package
.
You can add settings to any SwiftUI scene, for example to a Window
or WindowGroup
in a standard SwiftUI app.
The following example creates a simple settings window:
@main
struct SuperCoolApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
.settings {
// 1.1 - The "General" settings tab.
SettingsTab(.init("General", systemSymbol: .gearshape), id: "general-tab") {
// 1.2 - The "General" > "Appearance" settings subtab.
SettingsSubtab(.init("Appearance", systemSymbol: .circleLefthalfFilled), id: "appearance") {
AppearanceSettings()
}
// 1.2 - The "General" > "Composer" settings subtab.
SettingsSubtab(.init("Composer", systemSymbol: .person), id: "composer") {
ComposerSettings()
}
}
// 1.3 - An extension for the "General" settings tab.
SettingsTab(.extend(id: "general-tab"), id: "general-tab-extension") {
// 1.4 - The "General" settings subtab for no selection.
SettingsSubtab(.noSelection, id: "no-selection") {
NoSelectionInformation()
}
}
// 1.1 - The "Themes" settings tab.
SettingsTab(.init("Themes", systemSymbol: .paintbrush)) {
for theme in themes {
// 1.2 - A "Themes" > "THEME_NAME" settings subtab for each theme.
SettingsSubtab(.init(theme.title, systemSymbol: .paintbrush), id: theme.id) {
}
}
}
// 2.1 - The "+" and "-" buttons in the sidebar's toolbar.
.standardActions {
themes.append(.init())
} remove: { index in
if let index {
themes.remove(at: index)
}
}
}
}
}
1.1
- Create a new settings tab with the initializer forSettingsTab
inside thesettings(_:)
modifier on a scene.1.2
- Create a new settings subtab with the initializer forSettingsSubtab
inside aSettingsTab
initializer.1.3
- Extend an existing tab by using.extend(id:)
and providing the ID of the settings tab to extend.1.4
- Create a new settings subtab by using.noSelection
that is displayed if there is not a selected subtab.2.1
- Use the.standardActions(add:remove:options:)
modifier on a settings tab for adding a „+“, „-„ and optionally „⋯“ toolbar button to the sidebar. You can also add a custom toolbar with.actions(content:)
.
- SFSafeSymbols licensed under the MIT license
- SwiftLintPlugin licensed under the MIT license
- ColibriComponents licensed under the MIT license
- The contributors
- SourceDocs used for generating the docs
- SwiftLint for checking whether code style conventions are violated
- The programming language Swift