Created
April 27, 2022 11:06
-
-
Save sowenjub/e6b6b57095b036c1dcdddb0a0cf45636 to your computer and use it in GitHub Desktop.
Toggling a Diagnostic Mode button in SwiftUI using Settings.bundle
This file contains 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
struct SettingsSection: View { | |
@State var isShowingCloudLink = false | |
var body: some View { | |
Section { | |
if isShowingCloudLink { | |
NavigationLink(destination: CloudSettingsView()) { | |
Label(…) | |
} | |
} | |
} | |
.onReceive( | |
NotificationCenter.default | |
.publisher(for: UserDefaults.didChangeNotification) | |
.receive(on: RunLoop.main) | |
) { _ in | |
isShowingCloudLink = UserDefaults.standard.bool(forKey: "diagnostic_mode_enabled") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Read more here: https://sowenjub.me/writes/how-to-add-a-diagnostic-mode-using-settings-bundle-and-swiftui/