Skip to content

Repository files navigation

ModuleKit

ModuleKit is a Swift Package for modularizing your Swift codebase with customizable routes and actions. It is compatible with iOS, macOS, watchOS, and tvOS.

Installation

To install ModuleKit, add the following to your Package.swift file:

dependencies:[.package(url:"https://github.com/jsambuo/ModuleKit.git", from:"1.0.0")]

Usage

Defining a Module

Define a module by conforming to the Module protocol. Each module must provide an array of routes and an array of actions.

import ModuleKit
import SwiftUI
structMyModule:Module{varroutes:[Route]{[Route(path:"/my/route"){ parameters inVStack{Text("Route matched with parameters: \(parameters)")}},Route(path:"/simple/route"){VStack{Text("Simple route matched with no parameters")}}]}varactions:[Action]{[Action(key:"myAction"){ parameters inprint("My action executed with parameters: \(parameters)")}]}}

Using ModuleManager and RouteView

import SwiftUI
import ModuleKit
@mainstructMyApp:App{privateletmoduleManager=ModuleManager(modules:[MyModule()])varbody:someScene{WindowGroup{NavigationView{VStack{RouteView("/my/route", parameters:["param1":"value1"])RouteView("/simple/route")}.environmentObject(moduleManager)}}}}

API

ModuleManager

ModuleManager is responsible for managing and handling routes and actions for multiple modules.

publicclassModuleManager:ObservableObject{publicinit(modules:[anyModule]=[])publicfunc registerModule(_ module:anyModule)publicfunc registerModules(_ modules:[anyModule])publicfunc viewForRoute(path:String, parameters:[String:Any])->(anyView)?publicfunc performAction(key:String, parameters:[String:Any]=[:])}

RouteView

RouteView is a SwiftUI view that renders a view for a given route path using the ModuleManager.

publicstructRouteView:View{publicinit(_ path:String, parameters:[String:Any]=[:])}

License

ModuleKit is released under the MIT license. See LICENSE for details.

About

A Swift Package Manager (SPM) package for modularizing your Swift codebase with customizable routes and actions.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages