Skip to content

Package to add Coordinator protocols for SwiftUI architecture

Notifications You must be signed in to change notification settings

galbernator/SwiftUIProtocols

Repository files navigation

SwiftUIProtocols

This package is designed to work with an architecture that Jim Boyd and I developed for a production, large-scale, full-featured SwiftUI application. These protocols are designed to be used in an MVVM+Coordinator architecture and provide the functions of the coordinator. For an example of the architecture, check it out here.

Coordinator

Provides the initial view

@ViewBuilder func start() -> some View {
    ContentView()
}

Event Handler

Receives user interactions and processes them accordingly. Events are defined for each coordinator and essentially list the different actions a user can take from a specific screen. SwiftUI lifecylce events (e.g. - onAppear, onDisappear) are also usually detailed in the Events

enum Event {
    case onAppear
    case addButtonTapped
    case cancelButtonTapped
}

func send(_ event: Event) {
    switch event {
        case .onAppear:
            // Set handle anything that needs to be done one the view appears
        case .addButtonTapped:
            // Handle add button tap
        case .cancelButtonTapped:
            // Handle cancel button tap 
    }   
}

Navigator

Provides additional views for the current screen. Destinations are defined for each coordinator and essentiall list the different paths able to be reached from the current screen.

enum Destination {
    case addItem
    case tooltipModal
}

@ViewBuilder func view(for destination: Destination) -> some View {
    switch destination {
        case .addItem:
            AddItemView()
        case .tooltipModal:
            TooltipView()
    }
}

About

Package to add Coordinator protocols for SwiftUI architecture

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages