Skip to content

Commit 0e2be7e

Browse files
committed
Improve deprecation warnings for old binding helpers (#774)
* Improve deprecation warnings for old binding helpers * wip * wip * wip * esc * wip
1 parent 69f1bdc commit 0e2be7e

File tree

1 file changed

+44
-10
lines changed

1 file changed

+44
-10
lines changed

Sources/ComposableArchitecture/Internal/Deprecations.swift

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ import SwiftUI
77

88
#if compiler(>=5.4)
99
extension BindingAction {
10-
@available(*, deprecated, message: "Values are now wrapped in 'BindableState'")
10+
@available(
11+
*, deprecated,
12+
message:
13+
"For improved safety, bindable properties must now be wrapped explicitly in 'BindableState', and accessed via key paths to that 'BindableState', like '\\.$value'"
14+
)
1115
public static func set<Value>(
1216
_ keyPath: WritableKeyPath<Root, Value>,
1317
_ value: Value
@@ -21,7 +25,11 @@ import SwiftUI
2125
)
2226
}
2327

24-
@available(*, deprecated, message: "Values are now wrapped in 'BindableState'")
28+
@available(
29+
*, deprecated,
30+
message:
31+
"For improved safety, bindable properties must now be wrapped explicitly in 'BindableState', and accessed via key paths to that 'BindableState', like '\\.$value'"
32+
)
2533
public static func ~= <Value>(
2634
keyPath: WritableKeyPath<Root, Value>,
2735
bindingAction: Self
@@ -31,8 +39,13 @@ import SwiftUI
3139
}
3240

3341
extension Reducer {
34-
@available(*, deprecated, message: "'Reducer.binding()' no longer takes an explicit extract function and instead relies on 'BindableAction'")
35-
public func binding(action toBindingAction: @escaping (Action) -> BindingAction<State>?) -> Self {
42+
@available(
43+
*, deprecated,
44+
message:
45+
"'Reducer.binding()' no longer takes an explicit extract function and instead the reducer's 'Action' type must conform to 'BindableAction'"
46+
)
47+
public func binding(action toBindingAction: @escaping (Action) -> BindingAction<State>?) -> Self
48+
{
3649
Self { state, action, environment in
3750
toBindingAction(action)?.set(&state)
3851
return self.run(&state, action, environment)
@@ -42,8 +55,12 @@ import SwiftUI
4255

4356
#if canImport(SwiftUI)
4457
extension ViewStore {
58+
@available(
59+
*, deprecated,
60+
message:
61+
"For improved safety, bindable properties must now be wrapped explicitly in 'BindableState'. Bindings are now derived via dynamic member lookup to that 'BindableState' (for example, 'viewStore.$value'). For dynamic member lookup to be available, the view store's 'Action' type must also conform to 'BindableAction'."
62+
)
4563
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
46-
@available(*, deprecated, message: "Bindings are now derived using 'BindableState' and 'BindableAction'")
4764
public func binding<LocalState>(
4865
keyPath: WritableKeyPath<State, LocalState>,
4966
send action: @escaping (BindingAction<State>) -> Action
@@ -58,7 +75,11 @@ import SwiftUI
5875
#endif
5976
#else
6077
extension BindingAction {
61-
@available(*, deprecated, message: "Values are now wrapped in 'BindableState'. Upgrade to Xcode 12.5 or greater for access to 'BindableState'.")
78+
@available(
79+
*, deprecated,
80+
message:
81+
"For improved safety, bindable properties must now be wrapped explicitly in 'BindableState', and accessed via key paths to that 'BindableState', like '\\.$value'. Upgrade to Xcode 12.5 or greater for access to 'BindableState'."
82+
)
6283
public static func set<Value>(
6384
_ keyPath: WritableKeyPath<Root, Value>,
6485
_ value: Value
@@ -72,7 +93,11 @@ import SwiftUI
7293
)
7394
}
7495

75-
@available(*, deprecated, message: "Values are now wrapped in 'BindableState'. Upgrade to Xcode 12.5 or greater for access to 'BindableState'.")
96+
@available(
97+
*, deprecated,
98+
message:
99+
"For improved safety, bindable properties must now be wrapped explicitly in 'BindableState', and accessed via key paths to that 'BindableState', like '\\.$value'. Upgrade to Xcode 12.5 or greater for access to 'BindableState'."
100+
)
76101
public static func ~= <Value>(
77102
keyPath: WritableKeyPath<Root, Value>,
78103
bindingAction: Self
@@ -82,8 +107,13 @@ import SwiftUI
82107
}
83108

84109
extension Reducer {
85-
@available(*, deprecated, message: "'Reducer.binding()' no longer takes an explicit extract function and instead relies on 'BindableAction'. Upgrade to Xcode 12.5 or greater for access to 'Reducer.binding()' and 'BindableAction'.")
86-
public func binding(action toBindingAction: @escaping (Action) -> BindingAction<State>?) -> Self {
110+
@available(
111+
*, deprecated,
112+
message:
113+
"'Reducer.binding()' no longer takes an explicit extract function and instead the reducer's 'Action' type must conform to 'BindableAction'. Upgrade to Xcode 12.5 or greater for access to 'Reducer.binding()' and 'BindableAction'."
114+
)
115+
public func binding(action toBindingAction: @escaping (Action) -> BindingAction<State>?) -> Self
116+
{
87117
Self { state, action, environment in
88118
toBindingAction(action)?.set(&state)
89119
return self.run(&state, action, environment)
@@ -92,7 +122,11 @@ import SwiftUI
92122
}
93123

94124
extension ViewStore {
95-
@available(*, deprecated, message: "Bindings are now derived using 'BindableState' and 'BindableAction'. Upgrade to Xcode 12.5 or greater for access to 'BindableState' and 'BindableAction'.")
125+
@available(
126+
*, deprecated,
127+
message:
128+
"For improved safety, bindable properties must now be wrapped explicitly in 'BindableState'. Bindings are now derived via dynamic member lookup to that 'BindableState' (for example, 'viewStore.$value'). For dynamic member lookup to be available, the view store's 'Action' type must also conform to 'BindableAction'. Upgrade to Xcode 12.5 or greater for access to 'BindableState' and 'BindableAction'."
129+
)
96130
public func binding<LocalState>(
97131
keyPath: WritableKeyPath<State, LocalState>,
98132
send action: @escaping (BindingAction<State>) -> Action

0 commit comments

Comments
 (0)