Skip to content

Commit 82e580d

Browse files
committed
Fix Xcode 16.2 build error
1 parent f120c09 commit 82e580d

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

Sources/ArcGISToolkit/Extensions/SwiftUI/View+DefaultPreference.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import SwiftUI
1616

17+
#if swift(>=6.1) || swift(<6.0.3) // Xcode 16.2 (Swift 6.0.3) needs special handling
1718
/// Applies the preference's default value in the case that a value for the preference was not already specified.
1819
struct DefaultPreferenceModifier<K>: ViewModifier where K: PreferenceKey, K.Value: Equatable {
1920
@State private var value: K.Value?
@@ -33,3 +34,26 @@ extension View {
3334
modifier(DefaultPreferenceModifier<K>())
3435
}
3536
}
37+
#else
38+
/// Applies the preference's default value in the case that a value for the preference was not already specified.
39+
struct DefaultPreferenceModifier<K>: ViewModifier where K: PreferenceKey, K.Value: Equatable, K.Value: Sendable /* Xcode 16.2 requires Sendable */ {
40+
@State private var value: K.Value?
41+
42+
func body(content: Content) -> some View {
43+
content
44+
.onPreferenceChange(K.self) { value in
45+
Task { @MainActor in
46+
self.value = value
47+
}
48+
}
49+
.preference(key: K.self, value: value ?? K.defaultValue)
50+
}
51+
}
52+
53+
extension View {
54+
/// Confirms the default value for the given preference is set.
55+
func defaultPreference<K>(_: K.Type) -> some View where K: PreferenceKey, K.Value: Equatable, K.Value: Sendable /* Xcode 16.2 requires Sendable */ {
56+
modifier(DefaultPreferenceModifier<K>())
57+
}
58+
}
59+
#endif

0 commit comments

Comments
 (0)