An extremely lean implementation on the classic iOS router pattern.

Overview

Beeline

CI Version GitHub license Platform

Beeline is a very small library that aims to provide a lean, automatic implementation of the classic iOS router pattern. It extends UIViewController to retain a Router object that serves as the source of truth for controlling navigation flows for all of the view controller's children. When a child view controller wishes to transition to a new screen, it can call show() on itself and this request is passed up the view controller chain to the routing view controller.

Instructions

A very basic custom implementation looks as the following. First, we create a Swift enum conforming to Route where we can define the types of destinations with which we want to move:

enum AppRoute: Route {
    case viewController(number: Int)
}

Thanks to Swift associated enums, we can also include any custom parameters the new destination may need.

We then also make a new class which subclasses Router, which serves as our single point of truth for controlling the app flow based off the destinations we defined above:

public class AppRouter: Router {
    override func show(_ route: Route,
                        from sourceViewController: UIViewController?) -> Bool {

        // Optionally, filter out routes we don't support
        guard let appRoute = route as? AppRoute else { return false }

        // Check the requested enum, and perform the transition
        switch appRoute {
        case .viewController(let number):
            let newViewController = ViewController(number: number)
            sourceViewController?
                .navigationController?
                .pushViewController(newViewController, animated: true)
        }

        return true
    }
}

Using Objective-C associated objects, we can assign this router to any parent view controller that contains all of the view controllers that might want to perform these transitions:

let navigationController = UINavigationController(rootViewController: ViewController())
navigationController.router = AppRouter()

Finally, without any further modification to any of the child view controllers, they can start a transition by simply calling show() with the desired destination:

class ViewController: UIViewController {
    func moveToNewViewController() {
        show(AppRoute.viewController(number: 2))
    } 
} 

And that's the entire library! 🎉

Requirements

  • Swift 5
  • UIKit-compatible platforms (iOS, tvOS, Mac Catalyst)

Installation

Beeline is a very small framework, with all of its code contained in Router.swift. You can install it in the following ways:

Manual Installation

Drag the Beeline/Router.swift file into your Xcode project.

CocoaPods

pod 'Beeline'

SPM

I'll be adding this when I get the chance!

Carthage

No plans to support Carthage at the moment, but please consider filing a PR if you would like it!

Credits

Beeline was built as a component of iComics 2 by Tim Oliver

License

Beeline is available under the MIT License. Please check the LICENSE file for more information.

You might also like...
RxFlow is a navigation framework for iOS applications based on a Reactive Flow Coordinator pattern
RxFlow is a navigation framework for iOS applications based on a Reactive Flow Coordinator pattern

About Navigation concerns RxFlow aims to Installation The key principles How to use RxFlow Tools and dependencies GitHub Actions Frameworks Platform L

Protocol oriented, Cocoa UI abstractions based library that helps to handle view controllers composition, navigation and deep linking tasks in the iOS application. Can be used as the universal replacement for the Coordinator pattern.
DZURLRoute is an Objective-C implementation that supports standard-based URLs for local page jumps.

DZURLRoute Example To run the example project, clone the repo, and run pod install from the Example directory first. Requirements s.dependency 'DZVie

A simple, powerful and elegant implementation of the coordinator template in Swift for UIKit
A simple, powerful and elegant implementation of the coordinator template in Swift for UIKit

A simple, powerful and elegant implementation of the coordinator template in Swift for UIKit Installation Swift Package Manager https://github.com/bar

🎯Linker  Lightweight way to handle internal and external deeplinks in Swift for iOS
🎯Linker Lightweight way to handle internal and external deeplinks in Swift for iOS

Linker Lightweight way to handle internal and external deeplinks in Swift for iOS. Installation Dependency Managers CocoaPods CocoaPods is a dependenc

Provides a custom presentation modifier that provides more options including full screen presentations. (iOS)

Presentation Also available as a part of my SwiftUI+ Collection – just add it to Xcode 13+ Provides a custom presentation modifier that provides more

iOS routing done right. Handles both URL recognition and controller displaying with parsed parameters. All in one line, controller stack preserved automatically!
iOS routing done right. Handles both URL recognition and controller displaying with parsed parameters. All in one line, controller stack preserved automatically!

Developed and Maintained by Ipodishima Founder & CTO at Wasappli Inc. (If you need to develop an app, get in touch with our team!) So what is this lib

An easier way to handle third-party URL schemes in iOS apps.
An easier way to handle third-party URL schemes in iOS apps.

IntentKit ========= IntentKit is an easier way to handle third-party URL schemes in iOS apps. Linking to third-party apps is essentially broken on iOS

URL routing library for iOS with a simple block-based API

JLRoutes What is it? JLRoutes is a URL routing library with a simple block-based API. It is designed to make it very easy to handle complex URL scheme

Comments
  • Improvements to the Router

    Improvements to the Router

    • Changed the Router's accessibility from public to open
    • Completed the commenting on the Router's methods
    • Added unit tests
    • Fixed a bug where view controllers already with a router would be overridden by a default one, if it existed.
    opened by TimOliver 0
Owner
Tim Oliver
Gamer. Developer. Geek. Senior Software Engineer at @Drivemode (prev. @Realm). Lover of writing iOS code and singer of bad karaoke. 日本語もオッケ〜
Tim Oliver
Marshroute is an iOS Library for making your Routers simple but extremely powerful

Marshroute Contents Overview Detailes Tuning the transition animation 3d touch support PeekAndPopUtility Peek and pop state observing Demo Requirement

avito.tech 215 Jan 4, 2023
SwiftRouter - A URL Router for iOS, written in Swift

SwiftRouter A URL Router for iOS, written in Swift, inspired by HHRouter and JLRoutes. Installation SwiftRouter Version Swift Version Note Before 1.0.

Chester Liu 259 Apr 16, 2021
Crossroad is an URL router focused on handling Custom URL Scheme

Crossroad is an URL router focused on handling Custom URL Scheme. Using this, you can route multiple URL schemes and fetch arguments and parameters easily.

Kohki Miki 331 May 23, 2021
A demonstration to the approach of leaving view transition management to a router.

SwiftUI-RouterDemo This is a simplified demonstration to the approach of leaving view transition management to a router.

Elvis Shi 3 May 26, 2021
An experimental navigation router for SwiftUI

SwiftUIRouter ?? An ⚠️ experimental ⚠️ navigation router for SwiftUI Usage ?? Check out ExampleApp for more. Define your routes: import SwiftUIRouter

Orkhan Alikhanov 16 Aug 16, 2022
URLScheme router than supports auto creation of UIViewControllers for associated url parameters to allow creation of navigation stacks

IKRouter What does it do? Once you have made your UIViewControllers conform to Routable you can register them with the parameters that they represent

Ian Keen 94 Feb 28, 2022
Interface-oriented router for discovering modules, and injecting dependencies with protocol in Objective-C and Swift.

ZIKRouter An interface-oriented router for managing modules and injecting dependencies with protocol. The view router can perform all navigation types

Zuik 631 Dec 26, 2022
Helm - A graph-based SwiftUI router

Helm is a declarative, graph-based routing library for SwiftUI. It fully describ

Valentin Radu 99 Dec 5, 2022
A bidirectional Vapor router with more type safety and less fuss.

vapor-routing A routing library for Vapor with a focus on type safety, composition, and URL generation. Motivation Getting started Documentation Licen

Point-Free 68 Jan 7, 2023
A bidirectional router with more type safety and less fuss.

swift-url-routing A bidirectional URL router with more type safety and less fuss. This library is built with Parsing. Motivation Getting started Docum

Point-Free 242 Jan 4, 2023