Swiftpack.co -  Package - hhru/Nivelir
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
hhru/Nivelir
A Swift DSL for navigation in iOS and tvOS apps with a simplified, chainable, and compile time safe syntax
.package(url: "https://github.com/hhru/Nivelir.git", from: "1.0.0-alpha.2")

Nivelir

Build Status Cocoapods Carthage compatible SPM compatible Platforms Xcode Swift License

Nivelir is a DSL for navigation in iOS and tvOS apps with a simplified, chainable, and compile time safe syntax.

Contents

Requirements

  • iOS 10.0+ / tvOS 10.0+
  • Xcode 11+
  • Swift 5.1+

Installation

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

To integrate Nivelir into your Xcode project using CocoaPods, specify it in your Podfile:

platform :ios, '10.0'
use_frameworks!

target '<Your Target Name>' do
    pod 'Nivelir', '~> 1.0.0-alpha.2'
end

Finally run the following command:

$ pod install

Carthage

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks. You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

To integrate Nivelir into your Xcode project using Carthage, specify it in your Cartfile:

github "hhru/Nivelir" ~> 1.0.0-alpha.2

Finally run carthage update to build the framework and drag the built Nivelir.framework into your Xcode project.

Swift Package Manager

The Swift Package Manager is a tool for managing the distribution of Swift code. It’s integrated with the Swift build system to automate the process of downloading, compiling, and linking dependencies.

To integrate Nivelir into your Xcode project using Swift Package Manager, add the following as a dependency to your Package.swift:

.package(url: "https://github.com/hhru/Nivelir.git", from: "1.0.0-alpha.2")

Then specify "Nivelir" as a dependency of the Target in which you wish to use Nivelir.

Here's an example Package.swift:

// swift-tools-version:5.0
import PackageDescription

let package = Package(
    name: "MyPackage",
    products: [
        .library(name: "MyPackage", targets: ["MyPackage"])
    ],
    dependencies: [
        .package(url: "https://github.com/hhru/Nivelir.git", from: "1.0.0-alpha.2")
    ],
    targets: [
        .target(name: "MyPackage", dependencies: ["Nivelir"])
    ]
)

Usage

Quick Start

Let's implement a simple view controller that can set the background color:

class SomeViewController: UIViewController {

    let color: UIColor

    init(color: UIColor) {
        self.color = color

        super.init(nibName: nil, bundle: nil)
    }

    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        view.backgroundColor = color
    }
}

Next, we need to implement a builder that creates our controller:

struct SomeScreen: Screen, ScreenPayloadAssociating {

    let color: UIColor

    func build(navigator: ScreenNavigator) -> UIViewController {
        SomeViewController(color: color)
    }
}

Now we can use this screen in navigation:

let navigator = DefaultScreenNavigator()

navigator.navigate(fromTop: .stackContainer) { route in
    route
        .popToRoot()
        .push(SomeScreen(color: .red))
        .push(SomeScreen(color: .green)) { route in
            route.present(SomeScreen(color: .blue))
        }
}

This navigation performs the following steps:

  • Search for the topmost container of the stack (UINavigationController)
  • Resetting its stack to the first screen
  • Adding a red screen to the stack
  • Adding a green screen to the stack
  • Presenting a blue screen on the green screen modally

Communication

  • If you need help, open an issue.
  • If you found a bug, open an issue.
  • If you have a feature request, open an issue.
  • If you want to contribute, submit a pull request.

License

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

GitHub

link
Stars: 55
Last commit: 5 weeks ago

Release Notes

1.0.0-alpha.2
5 weeks ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco