Back to Swiftgen

Segues Swift5

Documentation/templates/ib/segues-swift5.md

6.6.32.7 KB
Original Source

Template Information

NameDescription
File nameib/segues-swift5.stencil
Configuration example<pre>ib:
inputs: dir/to/search/for/storyboards
outputs:
templateName: segues-swift5
output: Storyboard Segues.swift</pre> |

| Language | Swift 5 | | Author | Olivier Halligon |

When to use it

  • When you need to generate Swift 5 code for your storyboard segues.
  • The generated code supports both UIKit platforms (iOS, tvOS and watchOS) and AppKit platform (macOS).
  • Note: if you also need to generate code for your storyboard scenes, you can use scenes-swift5 in addition to this one.

Customization

You can customize some elements of this template by overriding the following parameters when invoking swiftgen. See the dedicated documentation.

Parameter NameDefault ValueDescription
enumNameStoryboardSegueAllows you to change the name of the generated enum containing all storyboard segues.
ignoreTargetModuleN/ASetting this parameter will disable the behaviour of prefixing classes with their module name for (only) the target module.
moduleN/ABy default, the template will import the needed modules for custom classes, but won’t import the target’s module to avoid an import warning — using the PRODUCT_MODULE_NAME environment variable to detect it. Should you need to ignore an additional module, you can provide it here.
publicAccessN/AIf set, the generated constants will be marked as public. Otherwise, they'll be declared internal.

Generated Code

Note: the generated code may look differently depending on the platform the storyboard file is targeting.

Extract:

swift
internal enum StoryboardSegue {
  internal enum Message: String, SegueType {
    case customBack = "CustomBack"
    case embed = "Embed"
    case nonCustom = "NonCustom"
    case showNavCtrl = "Show-NavCtrl"
  }
}

Full generated code

Usage example

swift
// You can perform segues using:
vc.perform(segue: StoryboardSegue.Message.embed)

// or match them (in prepareForSegue):
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
  switch StoryboardSegue.Message(segue) {
  case .embed?:
    // Prepare for your custom segue transition, passing information to the destionation VC
  case .customBack?:
    // Prepare for your custom segue transition, passing information to the destionation VC
  default:
    // Other segues from other scenes, not handled by this VC
    break
  }
}