Skip to content

Convenient methods for performing storyboards segues. without override "prepareForSegue" method

License

Notifications You must be signed in to change notification settings

dhrebeniuk/SegueWithCompletion

Repository files navigation

SegueWithCompletion

SegueWithCompletion is UIViewController extension that provides ability perform segue and clarify setup viewcontroller parameters without override prepareForSegue method.

Installation

Via CocoaPods:

pod 'SegueWithCompletion'

Storyboard Usage

Present UIViewContreoller

Change perform your's segues from this:

func openFooScreen() {
    self.performSegue(withIdentifier: "fooSegue", sender: nil);
}

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if let fooController = segue.destination as? FooViewController, segue.identifier == "fooSegue" {
        fooController.settings = Settings()
    }
}

To this:

func openFooScreen() {
    self.perform(segue: "fooSegue") { (fooController: FooViewController) in
		fooController.settings = Settings()
    }
}

Present UIViewContreoller with UINavigationController

Change perform your's segues from this:

func openBarScreen() {
    self.performSegue(withIdentifier: "barSegue", sender: nil);
}

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if let barNavigationController = segue.destination as? UINavigationController, segue.identifier == "fooSegue" {
        if let barController = barNavigationController.topViewController as? BarViewController {
            barController.settings = Settings()
        }
    }
}

To this:

func openBarScreen() {
    self.performWithNavigationController(segue: "barSegue") { (barController: BarViewController) in
        barController.settings = Settings()
    })
}

Compatibility/Restrictions

  • iOS8+ only

About

Convenient methods for performing storyboards segues. without override "prepareForSegue" method

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published