Created
January 8, 2025 03:37
-
-
Save khcrysalis/0ec18318e117e0c471bc46426ea47d1f to your computer and use it in GitHub Desktop.
Wrapper for various ways to access settings in SwiftUI.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
struct SettingsLinkWrapper<Label>: View where Label: View { | |
private var label: Label | |
init(@ViewBuilder label: () -> Label) { | |
self.label = label() | |
} | |
var body: some View { | |
if #available(macOS 14, *) { | |
#if os(macOS) | |
SettingsLink { label } | |
#endif | |
} else { | |
Button(action: { | |
#if os(macOS) | |
NSApp.sendAction(Selector(("showPreferencesWindow:")), to: nil, from: nil) | |
#endif | |
}) { | |
label | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment