Latest 0.9.0
Homepage https://github.com/npu3pak/ios-lib-segue-coordinator
License MIT
Platforms ios 9.0
Authors

Version
License
Platform

Complete API reference

Alternative to Application Coordinator pattern. Create separate classes that will handle navigation instead of view controllers.

Remove navigation from view controllers.

Controllers no longer need to know anything about each other. If the controller needs to show some data in another controller, it calls a closure and passes data into it. SegueCoordinator handles this closure, shows the desired controller and populates it with data.

Split application into parts.

You can create multiple coordinators for different business processes and reuse them. SegueCoordinator can become a good entry point for these processes.

Remove the boilerplate code. Increase readability.

SegueCoordinator allows you to perform typical navigation tasks like push, segue, modal in a compact and consistent manner.

Requirements

  • iOS 9+
  • Swift 5
  • XCode 10.2+

Installation

SegueCoordinator is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod 'SegueCoordinator'

Usage

1. Prepare controllers

Create Main.storyboard with initial ListViewController and DetailsViewController. Add segue with identifier "ShowDetails" from list to details.

class ListViewController: UIViewController {

    var onShowDetails: ((String)->Void)?

    func showDetails() {
        onShowDetails?("Data")
    }
}

class DetailsViewController: UIViewController {

    var details: String!

    override func viewDidLoad() {
        super.viewDidLoad()

        // show details text here
    }
}

IMPORTANT

If you override prepareForSegue method, be sure to call super.prepareForSegue

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    super.prepare(for: segue, sender: sender)
}

2. Create coordinator

import SegueCoordinator

class MainCoordinator: SegueCoordinator {
    init(rootNavigationController: UINavigationController) {
        super.init(storyboardName: "Main", rootNavigationController: rootNavigationController)
    }

    func start() {
        setInitial(type: ListViewController.self) {
            $0.onShowDetails =  { [unowned self] in self.showDetails($0) }
        }
    }

    func showDetails(_ details: String) {
        segue("ShowDetails", type: DetailsViewController.self) {
            $0.details = details
        }
    }
}

3. Configure AppDelegate

class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?
    private var mainCoordinator: MainCoordinator?

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        let rootNavigationController = UINavigationController()
        window?.rootViewController = rootNavigationController
        window?.makeKeyAndVisible()

        mainCoordinator = MainCoordinator(rootNavigationController: rootNavigationController)
        mainCoordinator?.start()
        return true
    }
}

Complete API reference

https://npu3pak.github.io/ios-lib-segue-coordinator/Classes/SegueCoordinator.html

Example

To run the example project, clone the repo, and run pod install from the Example directory.

Author

Evgeniy Safronov, [email protected]

License

SegueCoordinator is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "SegueCoordinator",
    "platforms": {
        "ios": "9.0"
    },
    "version": "0.9.0",
    "summary": "Create separate classes that will handle navigation instead of view controllers",
    "homepage": "https://github.com/npu3pak/ios-lib-segue-coordinator",
    "documentation_url": "https://npu3pak.github.io/ios-lib-segue-coordinator",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Evgeniy Safronov": "[email protected]"
    },
    "source": {
        "git": "https://github.com/npu3pak/ios-lib-segue-coordinator.git",
        "tag": "0.9.0"
    },
    "swift_versions": "5.0",
    "source_files": "SegueCoordinator/Classes/**/*",
    "description": "Alternative to Application Coordinator pattern. Create separate classes that will handle navigation instead of view controllers."
}

Pin It on Pinterest

Share This