Skip to content

Commit

Permalink
Minor tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed May 14, 2024
1 parent d8a954e commit 3b770e2
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions Sources/Defaults/SwiftUI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ extension Defaults {
task?.cancel()
}

func observe() {
private func observe() {
// We only use this on the latest OSes (as of adding this) since the backdeploy library has a lot of bugs.
if #available(macOS 13, iOS 16, tvOS 16, watchOS 9, visionOS 1.0, *) {
task?.cancel()
Expand All @@ -44,7 +44,7 @@ extension Defaults {
return
}

self.objectWillChange.send()
objectWillChange.send()
}
}
} else {
Expand Down Expand Up @@ -221,12 +221,26 @@ extension Defaults {
}

extension Defaults.Toggle<Text> {
public init(_ title: some StringProtocol, key: Defaults.Key<Bool>) {
public init(
_ title: some StringProtocol,
key: Defaults.Key<Bool>
) {
self.label = { Text(title) }
self.observable = .init(key)
}
}

extension Defaults.Toggle<Label<Text, Image>> {
public init(
_ title: some StringProtocol,
systemImage: String,
key: Defaults.Key<Bool>
) {
self.label = { Label(title, systemImage: systemImage) }
self.observable = .init(key)
}
}

extension Defaults.Toggle {
/**
Do something when the value changes to a different value.
Expand Down

0 comments on commit 3b770e2

Please sign in to comment.