StoryboardLoader

public protocol StoryboardLoader

Protocol to be adopted by a class that gives easy loading of UIViewControllers from multiple UIStoryboards.

Two enum types are specified that should be used to identify each UIViewController and the Storyboard from which it can be loaded. The app specific adopter should then implement:

  • storyboardIdentifierForViewControllerIdentifier(_:)

typically using a switch statement, to ensure exhaustive coverage of all UIViewControllers declared at compile time. There is a defualt implementation for

  • instantiateViewControllerForIdentifier(_:bundle:).

that should not need to be overriden.

There are defualt implementations for

  • storyboardNameForIdentifier(_:)
  • viewControllerNameForIdentifier(_:)

where the enum types are backed by strings. These return the enum rawValues in those implementations.

  • storyboardNameForIdentifier(_:) Default implementation

    Should return the filename for the given identifier to be used in UIStoryboard(name:bundle:). Default implementation when StoryboardIdentifierType.RawValue == String returns storyboardID.rawValue.

    Default Implementation

    Returns the String rawValue of the identifier enum.

    Declaration

    Swift

    static func storyboardNameForIdentifier(storyboardID:StoryboardIdentifierType) -> String
  • The enum type used to identify multiplie UIStoryboards.

    Declaration

    Swift

    associatedtype StoryboardIdentifierType: RawRepresentable
  • viewControllerNameForIdentifier(_:) Default implementation

    Should return the UIViewController storyboard identifier for the given identifier to be used in UIStoryboard.instantiateViewControllerWithIdentifier(_:). Default implementation when ViewControllerIdentifierType.RawValue == String returns viewControllerID.rawValue.

    Default Implementation

    Returns the String rawValue of the identifier enum.

    Declaration

    Swift

    static func viewControllerNameForIdentifier(viewControllerID:ViewControllerIdentifierType) -> String
  • Should return the StoryboardIdentifierType that identifies the storyboard containing the UIViewController with the given identifier.

    Declaration

    Swift

    static func storyboardIdentifierForViewControllerIdentifier(viewControllerID:ViewControllerIdentifierType) -> StoryboardIdentifierType
  • Should create a new view controller from its containing Storyboard. A default implementation is provided.

    Default Implementation

    Default implementation provided to instantiate a UIViewController an enum, without needing knowledge of the UIStoryboard containing this UIViewController at the point of the loading code.

    Declaration

    Swift

    static func instantiateViewControllerForIdentifier(identifier:ViewControllerIdentifierType, bundle:NSBundle?) -> UIViewController

    Parameters

    identifier

    Should uniquely identify a UIStoryboard to load.

    bundle

    Optional bundle that contains the UIStoryboard. In the defualt implementation, this is optional and the default value is nil.

    Return Value

    A newly instantiated UIViewController. This crashes if there is no UIViewController with the given identifier in the UIStoryboard identified by storyboardIdentifierForViewControllerIdentifier(_:).