Latest 0.2.0
Homepage https://github.com/clmntcrl/swidux-router
License MIT
Platforms ios 10.0
Dependencies Swidux
Frameworks XCTest
Authors

Router driven by Swidux store.

SwiduxRouter

Usage

Declare your routes:

extension Route {
    static let home = Route(type: HomeViewController.self)
    static let product: (Id<Product>) -> Route = { Route(type: HomeViewController.self, routeParam: $0) }
    // ...
}

Prepare your Swidux store defining initial route:

struct AppState {
    var root = RootDescriptor(initialRoute: .home)
    // ...
}

let store = Store(
    initialState: AppState(),
    reducer: .combine(reducers: [
        routeReducer.lift(.root),
        // ...
    ])
)

Make your view controllers Routable or ParametricRoutable if it depends on parameters (for exemple a product page depend on a product id).

class HomeViewController: Routable {/* ... */}

class ProductViewController: ParametricRoutable {
    var routeParam: Id<Product>!
    // ...
}

Init your Router and add it to the view controller hierarchy:

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
    let window = UIWindow()

    func application(
        _ application: UIApplication,
        didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
    ) -> Bool {
        window.rootViewController = Router(
            store: store,
            keyPath: .root
        )
        window.makeKeyAndVisible()
        return true
    }
}

In order to route to new screens use store.dispatch with one of the following route action:

enum RouteAction: Action {
    case present(Route)
    case push(Route)
    case back
    case backToRoot
    case backTo(Route)
    case reset(RootDescriptor)
}

Known issues

  • Missing support for UITabBarController

Installation

Carthage

Add the following dependency to your Cartfile:

github "clmntcrl/swidux-router" ~> 0.2

CocoaPods

Add the following pod to your Podfile:

pod 'SwiduxRouter', '~> 0.2'

SwiftPM

Add the package as dependency in your Package.swift:

dependencies: [
    .package(url: "https://github.com/clmntcrl/swidux-router.git", from: "0.2.0"),
]

Create a xcode.xcconfig file, with the following content:

SUPPORTED_PLATFORMS = iphoneos iphonesimulator
IPHONEOS_DEPLOYMENT_TARGET = 10.0

Generate .xcodeproj:

swift package generate-xcodeproj --xcconfig-overrides xcode.xcconfig

License

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

Latest podspec

{
    "name": "SwiduxRouter",
    "version": "0.2.0",
    "summary": "iOS router driven by Swidux store.",
    "homepage": "https://github.com/clmntcrl/swidux-router",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Clu00e9ment Cyril": "[email protected]"
    },
    "social_media_url": "http://twitter.com/clmntcrl",
    "swift_version": "4.2",
    "platforms": {
        "ios": "10.0"
    },
    "source": {
        "git": "https://github.com/clmntcrl/swidux-router.git",
        "tag": "0.2.0"
    },
    "frameworks": "XCTest",
    "source_files": [
        "Sources",
        "Sources/**/*.swift"
    ],
    "dependencies": {
        "Swidux": [
            "~> 1.0.0"
        ]
    }
}

Pin It on Pinterest

Share This