diff --git a/Example/ExampleApp/Sources/ErrorFeature/ErrorFeature.swift b/Example/ExampleApp/Sources/ErrorFeature/ErrorFeature.swift index 7490e1daf55ff0d125adc8ad5b067779dcd47cb9..756260a9d0e6da6e8c7e790f25568586c4fc795b 100644 --- a/Example/ExampleApp/Sources/ErrorFeature/ErrorFeature.swift +++ b/Example/ExampleApp/Sources/ErrorFeature/ErrorFeature.swift @@ -2,7 +2,11 @@ import ComposableArchitecture import SwiftUI public struct ErrorState: Equatable { - public init() {} + public init(error: NSError) { + self.error = error + } + + var error: NSError } public enum ErrorAction: Equatable {} diff --git a/Example/ExampleApp/Sources/ErrorFeature/ErrorView.swift b/Example/ExampleApp/Sources/ErrorFeature/ErrorView.swift index bc86d99c96c44a0d70a5eb8532a1b7fc9295d5a6..35d9b84785a2906d677008ea64440a4952f84654 100644 --- a/Example/ExampleApp/Sources/ErrorFeature/ErrorView.swift +++ b/Example/ExampleApp/Sources/ErrorFeature/ErrorView.swift @@ -7,14 +7,33 @@ public struct ErrorView: View { } let store: Store<ErrorState, ErrorAction> + @Environment(\.dismiss) var dismiss struct ViewState: Equatable { - init(state: ErrorState) {} + let error: NSError + + init(state: ErrorState) { + error = state.error + } } public var body: some View { WithViewStore(store.scope(state: ViewState.init)) { viewStore in - Text("ErrorView") + NavigationView { + Form { + Text("\(viewStore.error)") + } + .navigationTitle("Error") + .toolbar { + ToolbarItem(placement: .cancellationAction) { + Button { + dismiss() + } label: { + Image(systemName: "xmark") + } + } + } + } } } } @@ -23,7 +42,9 @@ public struct ErrorView: View { public struct ErrorView_Previews: PreviewProvider { public static var previews: some View { ErrorView(store: .init( - initialState: .init(), + initialState: .init( + error: NSError(domain: "preview", code: 1234) + ), reducer: .empty, environment: () ))