|  | 
| 3 | 3 | ## How to install this package  | 
| 4 | 4 | 
 | 
| 5 | 5 | + Open your project on Xcode | 
| 6 |  | -+ Go to Project Tab and select "Package Dependencies" | 
| 7 |  | -+ Click "+" and search this package with use git clone url | 
|  | 6 | ++ Go to the Project Tab and select "Package Dependencies" | 
|  | 7 | ++ Click "+" and search this package with use git clone URL | 
| 8 | 8 | + Don't change anything and click Add Package | 
| 9 | 9 | + The package will be attached to the targeted application | 
| 10 | 10 | 
 | 
| 11 | 11 | ## How to use this package | 
| 12 |  | -### Create a ViewModel conforming to the ErrorableViewModelProtocol | 
|  | 12 | +### Create a ViewModel conforming to the ErrorableBaseViewModel | 
| 13 | 13 | <b>Note:<b> The class includes AnyObject and ObservableObject! | 
| 14 | 14 | 
 | 
| 15 | 15 | ```swift | 
| 16 |  | -final class TestViewModel: ErrorableViewModelProtocol { | 
| 17 |  | -    @Published var state: PageStates = .loading | 
| 18 |  | - | 
| 19 |  | -    func refresh() { | 
| 20 |  | -        // TODO: Write here your refresh action | 
| 21 |  | -        // TODO: Don't forget to update the state property in the refresh action | 
| 22 |  | -    } | 
|  | 16 | +private final class ExampleViewModel: ErrorableBaseViewModel { | 
|  | 17 | +    // Your actions will come here | 
| 23 | 18 | } | 
| 24 | 19 | ``` | 
| 25 |  | -### Create SwiftUI and conform to the ErrorableViewProtocol | 
| 26 |  | -- Set the ViewModel typealias to the view model we created | 
| 27 |  | -- Create the Viewmodel as @ObservedObject. | 
| 28 |  | -- Use the createErrorableView function according to your need. | 
|  | 20 | +### Create a SwiftUI view that conforms to the ErrorableView or ErrorableSheetView Protocols. (Usage is the same for both protocols.) | 
| 29 | 21 | ```swift | 
| 30 |  | -struct ContentView: ErrorableViewProtocol { | 
| 31 |  | -    typealias Content = AnyView | 
| 32 |  | -    typealias ViewModel = TestViewModel | 
| 33 |  | -    @ObservedObject var viewModel: TestViewModel = TestViewModel() | 
| 34 |  | -     | 
| 35 |  | -    var body: some View { | 
| 36 |  | -        NavigationView { | 
| 37 |  | -            createErrorableView(errorTitle: "Upps!", errorSubTitle: "We encountered an error.\n Please try again later!", errorSystemIcon: "minus.diamond.fill", errorButtonTitle: "Try Again") { | 
| 38 |  | -                AnyView ( | 
| 39 |  | -                    ScrollView { | 
| 40 |  | -                        ForEach(0..<100, id: \.self) { _ in | 
| 41 |  | -                            AsyncImage(url: URL(string: "https://picsum.photos/200")) { phase in | 
| 42 |  | -                                if let image = phase.image { | 
| 43 |  | -                                    image | 
| 44 |  | -                                        .resizable() | 
| 45 |  | -                                        .scaledToFill() | 
| 46 |  | -                                } else { | 
| 47 |  | -                                    Color.gray | 
| 48 |  | -                                } | 
| 49 |  | -                            }.frame(width: 300, height: 200, alignment: .center) | 
| 50 |  | -                                .clipped() | 
| 51 |  | -                        } | 
| 52 |  | -                    }.frame(width: UIScreen.main.bounds.width) | 
| 53 |  | -                ) | 
| 54 |  | -            } | 
| 55 |  | -            .navigationTitle("Example") | 
| 56 |  | -        }.onAppear { | 
| 57 |  | -            Task { @MainActor in | 
| 58 |  | -                DispatchQueue.main.asyncAfter(deadline: .now() + 2) { | 
| 59 |  | -                    viewModel.state = .failure | 
| 60 |  | -                } | 
| 61 |  | -            } | 
|  | 22 | +private struct SimpleExampleView: ErrorableView { | 
|  | 23 | +    typealias ViewModel = ExampleViewModel | 
|  | 24 | +    @ObservedObject var viewModel: ExampleViewModel = ExampleViewModel() | 
|  | 25 | + | 
|  | 26 | +    var content: some View { | 
|  | 27 | +        VStack { | 
|  | 28 | +            Text("Loaded Statement!") | 
| 62 | 29 |         } | 
| 63 | 30 |     } | 
| 64 | 31 | } | 
| 65 | 32 | ``` | 
| 66 | 33 | 
 | 
| 67 |  | -## Demo Images | 
|  | 34 | +## ErrorableView Demo Images | 
|  | 35 | +<div> | 
|  | 36 | +  <img width = 255 height = 525 src="https://github.com/devmehmetates/ErrorableView-SwiftUI/assets/74152011/5dc340f8-e455-46f9-9504-e3fcc6faf3a5"> | 
|  | 37 | +  <img width = 255 height = 525 src="https://github.com/devmehmetates/ErrorableView-SwiftUI/assets/74152011/f4c4b650-87fb-4b51-a305-c550ba2db85b"> | 
|  | 38 | +  <img width = 255 height = 525 src="https://github.com/devmehmetates/ErrorableView-SwiftUI/assets/74152011/f28af8bb-dea2-4581-9770-ce7879e99925"> | 
|  | 39 | +</div> | 
|  | 40 | + | 
|  | 41 | +## ErrorableSheetView Demo Images | 
| 68 | 42 | <div> | 
| 69 |  | -  <img width = 255 src="https://github.com/devmehmetates/ErrorableView-SwiftUI/assets/74152011/f30a0d95-53a8-42e0-a21d-db67ef093b0e"> | 
| 70 |  | -  <img width = 255 src="https://github.com/devmehmetates/ErrorableView-SwiftUI/assets/74152011/269ad7d4-ae61-40bc-a731-7dd87f116a4d"> | 
| 71 |  | -  <img width = 255 src="https://github.com/devmehmetates/ErrorableView-SwiftUI/assets/74152011/155a174f-dade-4bba-ba4b-dec12dfa6d7f"> | 
|  | 43 | +  <img width = 255 height = 525 src="https://github.com/devmehmetates/ErrorableView-SwiftUI/assets/74152011/5dc340f8-e455-46f9-9504-e3fcc6faf3a5"> | 
|  | 44 | +  <img width = 255 height = 525 src="https://github.com/devmehmetates/ErrorableView-SwiftUI/assets/74152011/3631f105-c1c2-4b71-9895-6a442e2b2dca"> | 
|  | 45 | +  <img width = 255 height = 525 src="https://github.com/devmehmetates/ErrorableView-SwiftUI/assets/74152011/f28af8bb-dea2-4581-9770-ce7879e99925"> | 
| 72 | 46 | </div> | 
0 commit comments