Latest 3.0.0-beta.2
Homepage https://github.com/langyanduan/SegueKit
License MIT
Platforms ios 8.0
Authors

CI Status
Version
License
Platform

⚠️ This readme describes SegueKit 3.0 version that requires Swift 3.0.
⚠️ If you are looking for Swift 2.3 compatible version, please take a look at SegueKit ~> 2.0 versions and swift2.3 branch.

About me

Perform storyboard segues with closures.

Why use this?

If you want to pass some parameters to destination view controller which created by segue in storyboard, usual should override prepareForSegue:sender:. But if work with SegueKit, you can do it in closure.

Usage

If you create a segue in storyboard named "A", you can perfrom the segue like this:

import SegueKit

class ViewController: UIViewController {
    let disposeBag = DisposeBag()

    // basic
    @IBAction func onBtnA(sender: AnyObject) {
        performSegue(with: "A") { (segue) in
            segue.destination.view.backgroundColor = UIColor.yellow
        }
    }
}

Extension Usage

  • with R.swfit
  • with Rx
  • with Rx + R.swift

Perform a segue with Extension

import SegueKit

class ViewController: UIViewController {
    let disposeBag = DisposeBag()

    // with R.swift
    @IBAction func onBtnB(sender: AnyObject) {
        performSegue(with: R.segue.viewController.b) { (segue) in
            segue.destination.view.backgroundColor = UIColor.green
        }
    }

    // with Rx
    @IBAction func onBtnC(sender: AnyObject) {
        rx.performSegue("C")
            .subscribeNext { (segue) in
                segue.destination.view.backgroundColor = UIColor.red
            }
            .addDisposableTo(disposeBag)
    }

    // with Rx + R.swift
    @IBAction func onBtnD(sender: AnyObject) {
        rx.performSegue(R.segue.viewController.d)
            .subscribeNext { (segue) in
                segue.destination.view.backgroundColor = UIColor.blue
            }
            .addDisposableTo(disposeBag)
    }
}

Rx binding

class A: UIViewController {

    let disposeBag = DisposeBag()
    @IBOutlet weak var button: UIButton!

    override func viewDidLoad() {
        super.viewDidLoad()

        // with Rx
        button.rx.tap.bindTo(rx.segue("A")) { (segue, _) in
            segue.destination.view.backgroundColor = UIColor.black
        }.addDisposableTo(disposeBag)
    }
}

class B: UIViewController {

    let disposeBag = DisposeBag()
    @IBOutlet weak var button: UIButton!

    override func viewDidLoad() {
        super.viewDidLoad()

        // with Rx + R.swift
        button.rx.tap.bindTo(rx.segue(R.segue.b.b)) { (segue, _) in
            segue.destination.view.backgroundColor = UIColor.brown
        }.addDisposableTo(disposeBag)
    }

}

Rx subscribe


import SegueKit

class C: UIViewController {
    let disposeBag = DisposeBag()

    override func viewDidLoad() {
        super.viewDidLoad()

        // with Rx
        rx.segue("C").subscribeNext { (segue, sender) in
            segue.destination.view.backgroundColor = UIColor.purple
        }.addDisposableTo(disposeBag)
    }
}

class D: UIViewController {
    let disposeBag = DisposeBag()

    override func viewDidLoad() {
        super.viewDidLoad()

        // with Rx + R.swift
        rx.segue(R.segue.d.d).subscribeNext { (segue, sender) in
            segue.destination.view.backgroundColor = UIColor.orange
        }.addDisposableTo(disposeBag)
    }
}

Example

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

Install

Cocoapods

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

  • Basic Functions

    pod "SegueKit", '~> 3.0.0-beta.1'
  • RxSwift

    pod "SegueKit/RxSwift", '~> 3.0.0-beta.1'
  • RxSwift

    pod "SegueKit/R.swift", '~> 3.0.0-beta.1'
  • RxSwift + R.swift

    pod "SegueKit/Extension", '~> 3.0.0-beta.1'

⚠️ If you want to use CocoaPods with Xcode 8.0 and Swift 3.0, you might need to add the following lines to your podfile:

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['SWIFT_VERSION'] = '3.0'
      config.build_settings['MACOSX_DEPLOYMENT_TARGET'] = '10.10'
    end
  end
end

Carthage

Because R.swift unsupport carthage, so SegueKit can only work with RxSwift if you install by crathage.

Carthage users can point to this repository and use whichever generated framework they’d like, SegueKit or RxSegueKit. The SegueKit framework is bundled in each of those frameworks; importing more than one framework in a single file will result in ambiguous lookups at compile time.

github "langyanduan/SegueKit"

License

SegueKit are created by langyanduan and released under a MIT License.

Latest podspec

{
    "name": "SegueKit",
    "version": "3.0.0-beta.2",
    "summary": "Perform storyboard segues with closures, support RxSwift and R.swift.",
    "description": "# SegueKitnnPerform storyboard segues with closures, support RxSwift and R.swift.nn## Why use this?nnbalabala...nn## Usagenn* basicn* with R.swfitn* with Rxn* with Rx + R.swift",
    "homepage": "https://github.com/langyanduan/SegueKit",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "langyanduan": "[email protected]"
    },
    "source": {
        "git": "https://github.com/langyanduan/SegueKit.git",
        "tag": "3.0.0-beta.2"
    },
    "social_media_url": "https://twitter.com/langyanduan",
    "platforms": {
        "ios": "8.0"
    },
    "default_subspecs": "Core",
    "subspecs": [
        {
            "name": "Core",
            "source_files": [
                "Sources/UIViewController+Swizzle.h",
                "Sources/UIViewController+Swizzle.m",
                "Sources/UIViewController+Segue.swift"
            ]
        },
        {
            "name": "R.swift",
            "source_files": [
                "Sources/UIViewController+R.swift.swift"
            ],
            "dependencies": {
                "SegueKit/Core": [],
                "R.swift": [
                    "~> 3.0.0"
                ]
            }
        },
        {
            "name": "RxSwift",
            "source_files": [
                "Sources/UIViewController+RxSwift.swift"
            ],
            "dependencies": {
                "SegueKit/Core": [],
                "RxSwift": [
                    "~> 3.0.0-beta.1"
                ],
                "RxCocoa": [
                    "~> 3.0.0-beta.1"
                ]
            }
        },
        {
            "name": "Extension",
            "source_files": [
                "Sources/UIViewController+Extension.swift"
            ],
            "dependencies": {
                "SegueKit/Core": [],
                "SegueKit/RxSwift": [],
                "SegueKit/R.swift": [],
                "R.swift": [
                    "~> 3.0.0"
                ],
                "RxSwift": [
                    "~> 3.0.0-beta.1"
                ],
                "RxCocoa": [
                    "~> 3.0.0-beta.1"
                ]
            }
        }
    ]
}

Pin It on Pinterest

Share This