Skip to content

Instantly share code, notes, and snippets.

@sowenjub
Created April 27, 2022 11:06
Show Gist options
  • Save sowenjub/e6b6b57095b036c1dcdddb0a0cf45636 to your computer and use it in GitHub Desktop.
Save sowenjub/e6b6b57095b036c1dcdddb0a0cf45636 to your computer and use it in GitHub Desktop.
Toggling a Diagnostic Mode button in SwiftUI using Settings.bundle
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")
}
}
}
@sowenjub
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment