Replies: 1 comment 10 replies
-
The The simplest would be to add a getter for the extraction: protocol AnalyticsTrackableAction {
static func analyticsTrack(_ event: AnalyticsEvent) -> Self
+ var analyticsTrack: AnalyticsEvent? { get }
} Conforming enums would get this for free if you mark them with +@dynamicMemberLookup
@CasePathable enum Action: AnalyticsTrackableAction {
case analyticsTrack(AnalyticsEvent)
} And then you would update your reducer operator: -guard let event: AnalyticsEvent = (/Action.analyticsTrack).extract(from: action) else {
+guard let event: AnalyticsEvent = action.analyticsTrack else { The alternative would be to constrain the protocol to protocol AnalyticsTrackableAction: CasePathable
where AllCasePaths: HasAnalyticsEventCasePath<Self> {}
protocol HasAnalyticsEventCasePath<Root> {
associatedtype Root: CasePathable
var analyticsEvent: AnyCasePath<Root, AnalyticsEvent> { get }
} And in practice you would need to extend both the action and its @CasePathable enum Action: AnalyticsTrackableAction {
case analyticsEvent(Bool)
}
extension Action.AllCasePaths: HasAnalyticsEventCasePath {} Note that in Swift <6 this extension needs to live in a separate file due to a bug with macros that was fixed in Swift 6. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello, I have a warning on a higher order reducer that says
'/' is deprecated: Use a 'CasePathable' case key path, instead.
How can I refactor
(/Action.analyticsTrack).extract(from: action)
to useCasePathable
?Swift 5.10
Beta Was this translation helpful? Give feedback.
All reactions