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 implementationShould return the filename for the given identifier to be used in
UIStoryboard(name:bundle:). Default implementation whenStoryboardIdentifierType.RawValue == StringreturnsstoryboardID.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 implementationShould return the
UIViewControllerstoryboard identifier for the given identifier to be used inUIStoryboard.instantiateViewControllerWithIdentifier(_:). Default implementation whenViewControllerIdentifierType.RawValue == StringreturnsviewControllerID.rawValue.Default Implementation
Returns the String rawValue of the identifier enum.
Declaration
Swift
static func viewControllerNameForIdentifier(viewControllerID:ViewControllerIdentifierType) -> String -
Should return the
StoryboardIdentifierTypethat identifies the storyboard containing theUIViewControllerwith the given identifier.Declaration
Swift
static func storyboardIdentifierForViewControllerIdentifier(viewControllerID:ViewControllerIdentifierType) -> StoryboardIdentifierType -
instantiateViewControllerForIdentifier(_:bundle:)Default implementationShould create a new view controller from its containing Storyboard. A default implementation is provided.
Default Implementation
Default implementation provided to instantiate a
UIViewControlleran enum, without needing knowledge of theUIStoryboardcontaining thisUIViewControllerat the point of the loading code.Declaration
Swift
static func instantiateViewControllerForIdentifier(identifier:ViewControllerIdentifierType, bundle:NSBundle?) -> UIViewControllerParameters
identifierShould uniquely identify a
UIStoryboardto load.bundleOptional 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 noUIViewControllerwith the given identifier in theUIStoryboardidentified bystoryboardIdentifierForViewControllerIdentifier(_:).
View on GitHub
StoryboardLoader Protocol Reference