TestsTested | ✗ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Feb 2016 |
SPMSupports SPM | ✗ |
Maintained by Ian Terrell.
Gemfile
gem "segue_handler_plugin"
Podfile
plugin 'segue_handler_plugin'
pod 'WillowTreeSegueHandler'
Build Phases Add a run script phase before the “Compile Sources” phase, with the following:
bundle exec pod --no-ansi --silent generate-segue-handlers $PROJECT_DIR $PROJECT_NAME
Build it once, then add the SegueExtensions.swift
file to your project and build again.
Segues with identifiers will be pulled out into nested enums in extensions on your view controllers, written to SegueExtensions.swift
.
Example generated code, assuming A
and B
are view controllers connected with from A
to B
via the segue with identifier "ToB"
.
extension A: SegueHandler {
enum SegueIdentifier: String {
case ToB
}
enum ToSegueDestination: SegueDestination {
case ToB(B)
init?(identifier: SegueIdentifier, destination: UIViewController) {
switch identifier {
case .ToB:
guard let vc = destination as? B else { return nil }
self = ToB(vc)
}
}
}
}
These can be used in your view controller like so:
func pushManually() {
performSegue(.ToB, sender: self)
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
switch segueFromStoryboardSegue(segue) {
case .ToB(let b):
b.prepare(dependency: "injected from a")
}
}
See the enclosed Example
application for a working demo.
Want to write amazing tvOS apps? Want to write amazing iOS apps? Check out our openings!