### Swift Package Manager Installation Source: https://github.com/hudishkin/vvsi/blob/main/README.md This snippet shows how to add the VVSI library to your project using the Swift Package Manager. It specifies the repository URL and the version to be included. ```swift dependencies: [ .package(url: "https://github.com/username/VVSI.git", from: "0.0.5") ] ``` -------------------------------- ### Create ListView with ViewState Integration (Swift) Source: https://github.com/hudishkin/vvsi/blob/main/README.md Demonstrates how to create a SwiftUI View that integrates with the VVSI architecture using ViewState. It displays a list of items, provides buttons to trigger actions (add, remove, random), and handles notifications for errors. ```swift // ListView.swift struct ListView: View { enum AlertType: Identifiable { var id: String { "\(self)" } case error(String) } @StateObject var viewState = ViewState(.init(), Interactor()) @State private var alertType: AlertType? = nil var body: some View { ForEach(viewState.state.items, id: \.self) { item in Text(item) } HStack { Button { viewState.trigger(.add) } label: { Text("Add") } Button { viewState.trigger(.remove) } label: { Text("Remove") } Button { viewState.trigger(.random(.init(count: Int.random(in: 1..<10), length: Int.random(in: 1..<5)))) } label: { Text("Random") } } .alert(item: $alertType) { item in switch item { case .error(let error): Alert( title: Text("Error"), message: Text(error), dismissButton: .default(Text("Ok")) ) } } .onReceive(viewState.notifications) { notification in switch notification { case .error(let message): alertType = .error(message) } } } } ``` -------------------------------- ### Define ListView State and Actions (Swift) Source: https://github.com/hudishkin/vvsi/blob/main/README.md Defines the state, actions, and options for a ListView component within the VVSI architecture. This includes defining the structure for options, the state properties, and the possible actions the view can trigger. ```swift // ListView+State.swift extension ListView { struct Options { let count: Int let length: Int } struct VState: StateProtocol { var items: [String] = [] } enum VAction: ActionProtocol { case add case remove case random(Options) } enum VNotification: NotificationProtocol { case error(String) } } ``` -------------------------------- ### Implement ListView Interactor Logic (Swift) Source: https://github.com/hudishkin/vvsi/blob/main/README.md Implements the business logic for the ListView using the Interactor component. It handles actions like adding, removing, and generating random items, interacting with the state and sending notifications. ```swift // ListView+Interactor.swift extension ListView { final class Interactor: ViewStateInteractorProtocol { typealias S = VState typealias A = VAction typealias N = VNotification let notifications: PassthroughSubject = .init() let service: Dependencies.Service init(dependencies: Dependencies = .shared) { service = dependencies.service } @MainActor func execute( _ state: @escaping CurrentState, _ action: VAction, _ updater: @escaping StateUpdater ) { switch action { case .add: Task.detached { [weak self] in guard await state().items.count < 5 else { self?.notifications.send(.error("Max items count is 5")) return } await updater { state in state.items.append("New item") } } case .remove: Task.detached { await updater { state in if !state.items.isEmpty { state.items.removeLast() } } } case .random(let opt): Task { let strings = (0..