13. // Storyboards.swift
extension UIStoryboard {
struct Scene {
enum Wizard : String, StoryboardScene {
static let storyboardName = "Wizard"
case CreateAccount = "CreateAccount"
static func createAccountViewController() -> CreateAccViewController {
return Wizard.CreateAccount.viewController() as! CreateAccViewController
}
case ValidatePassword = "Validate_Password"
static func validatePasswordViewController() -> UIViewController {
return Wizard.ValidatePassword.viewController()
}
}
enum Message : String, StoryboardScene {
static let storyboardName = "Message"
case Composer = "Composer"
static func composerViewController() -> UIViewController {
return Message.Composer.viewController()
}
case URLChooser = "URLChooser"
static func urlChooserViewController() -> XXPickerViewController {
return Message.URLChooser.viewController() as! XXPickerViewController
}
}
}
struct Segue {
enum Message : String {
case Custom = "Custom"
case Back = "Back"
case NonCustom = "NonCustom"
}
}
}
Storyboard IDに対応
Storyboardファイルに対応
via https://github.com/AliSoftware/SwiftGen
14. Usage
// Initial VC
let initialVC = UIStoryboard.Scene.Wizard.initialViewController()
// Generic ViewController constructor, returns a UIViewController instance
let validateVC = UIStoryboard.Scene.Wizard.ValidatePassword.viewController()
// Dedicated type var that returns the right type of VC (CreateAccViewController here)
let createVC = UIStoryboard.Scene.Wizard.createAccountViewController()
override func prepareForSegue(_ segue: UIStoryboardSegue, sender sender: AnyObject?) {
switch UIStoryboard.Segue.Message(rawValue: segue.identifier)! {
case .Custom:
// Prepare for your custom segue transition
case .Back:
// Prepare for your custom segue transition
case .NonCustom:
// Prepare for your custom segue transition
}
}
via https://github.com/AliSoftware/SwiftGen