Slide 1

Slide 1 text

Daiki Matsudate / TCAͰΘ͍Θ͍LTձ TCA Practice in 5 min New features you missed when migrating

Slide 2

Slide 2 text

x.com/d_date

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

Daiki Matsudate / TCAͰΘ͍Θ͍LTձ TCA Practice in 5 min New features you missed when migrating 4

Slide 9

Slide 9 text

Generics shorthands

Slide 10

Slide 10 text

Store

Slide 11

Slide 11 text

StoreOf

Slide 12

Slide 12 text

Reducer

Slide 13

Slide 13 text

ReducerOf

Slide 14

Slide 14 text

IdentifiedAction IdentifiedArray

Slide 15

Slide 15 text

IdentifiedActionOf IdentifiedArrayOf

Slide 16

Slide 16 text

StackAction

Slide 17

Slide 17 text

StackActionOf

Slide 18

Slide 18 text

StackActionOf Next Release

Slide 19

Slide 19 text

No content

Slide 20

Slide 20 text

ViewAction v1.7

Slide 21

Slide 21 text

ViewAction View͔Βݺͼग़͍ͨ͠ActionΛ੍ݶ͢Δ • ActionΛViewActionʹద߹ • Viewʹ@ViewAction(for:) ϚΫϩΛ͚ͭΔ • store.send(_: Action) Λ send(_: ViewAction) ʹมߋ • ʢvar storeΛpublicʹ͢Δ) public enum Action: ViewAction { case view(View) public enum View { case onAppear } } @ViewAction(for: Schedule.self) public struct ScheduleView: View { public var store:ɹStoreOf public var body: some View { ScrollView { … } .onAppear(perform: { send(.onAppear) }) } }

Slide 22

Slide 22 text

Implicit @CasePathable to enum v1.8

Slide 23

Slide 23 text

@Reducer struct Schedule { @ObservableState struct State: Equatable { var path = StackState() } enum Action { case path(StackActionOf) } var body: some View { Reduce { state, action in … } .forEach(\.path, action: \.path) { Path() } } } extension Schedule { @Reducer struct Path { @ObservableState enum State: Equatable { case detail(ScheduleDetail.State) } enum Action { case detail(ScheduleDetail.Action) } var body: some ReducerOf { Scope(state: \.detail, action: \.detail) { ScheduleDetail() } } } } @Reducer struct Schedule { @ObservableState struct State: Equatable { @Presents var destination: Destination.State? } enum Action { case destination(PresentationAction) } var body: some ReducerOf { Reduce { state, action in … } .ifLet(\.$destination, action: \.destination) { Destination() } } } extension Schedule { @Reducer struct Destination { @ObservableState enum State: Equatable { case detail(ScheduleDetail.State) } enum Action { case detail(ScheduleDetail.Action) } var body: some ReducerOf { Reduce { state, action in Scope(state: \.detail, action: \.detail) { ScheduleDetail() } } } …

Slide 24

Slide 24 text

@Reducer struct Schedule { @ObservableState struct State: Equatable { var path = StackState() } enum Action { case path(StackActionOf) } var body: some View { Reduce { state, action in … } .forEach(\.path, action: \.path) } } extension Schedule { @Reducer(state: .equatable) enum Path { case detail(ScheduleDetail.State) } } @Reducer struct Schedule { @ObservableState struct State: Equatable { @Presents var destination: Destination.State? } enum Action { case destination(PresentationAction) } var body: some ReducerOf { Reduce { state, action in … } .ifLet(\.$destination, action: \.destination) } } extension Schedule { @Reducer(state: .equatable) enum Destination { case detail(ScheduleDetail.State) } } …

Slide 25

Slide 25 text

Implicit @CasePathable to enum @Reducer enum Destination { case detail(Detail) }

Slide 26

Slide 26 text

Implicit @CasePathable to enum Note: Circular reference errors / Swift 5.10 @Reducer enum Destination { case detail(Detail) } extension Destination.State: Equatable {}

Slide 27

Slide 27 text

Implicit @CasePathable to enum @Reducer(state: .equatable) enum Destination { case detail(Detail) } Note: Circular reference errors / Swift 5.10

Slide 28

Slide 28 text

Direct dependency key value v1.9

Slide 29

Slide 29 text

@Dependency(\.apiClient)

Slide 30

Slide 30 text

@Dependency(\.apiClient) extension DependencyValues { public var apiClient: ApiClient { get { self[ApiClient.self] } set { self[ApiClient.self] = newValue } } }

Slide 31

Slide 31 text

@Dependency(ApiClient.self) v1.9

Slide 32

Slide 32 text

import Dependencies import DependenciesMacros import Foundation @DependencyClient public struct DataClient { public var fetchData: @Sendable () throws -> Conference public var fetchSpeaker: @Sendable (_ name: String) throws -> Speaker? } extension DataClient: DependencyKey { static public var liveValue: DataClient = .init( fetchData: { // fetch data return response }, fetchSpeaker: { // fetch Speaker } ) }

Slide 33

Slide 33 text

New features you missed when migrating • Generics shorthands • StackActionOf (Next release) • ViewAction (v1.7) • Implicit @CasePathable to enum (v1.8) • Direct dependency key value (v1.9)