StoryboardLoader
public protocol StoryboardLoader
Protocol to be adopted by a class that gives easy loading of UIViewController
s from multiple UIStoryboard
s.
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 rawValue
s in those implementations.
-
storyboardNameForIdentifier(_:)
Default implementationShould return the filename for the given identifier to be used in
UIStoryboard(name:bundle:)
. Default implementation whenStoryboardIdentifierType.RawValue == String
returnsstoryboardID.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
UIStoryboard
s.Declaration
Swift
associatedtype StoryboardIdentifierType: RawRepresentable
-
viewControllerNameForIdentifier(_:)
Default implementationShould return the
UIViewController
storyboard identifier for the given identifier to be used inUIStoryboard.instantiateViewControllerWithIdentifier(_:)
. Default implementation whenViewControllerIdentifierType.RawValue == String
returnsviewControllerID.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 theUIViewController
with 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
UIViewController
an enum, without needing knowledge of theUIStoryboard
containing thisUIViewController
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 noUIViewController
with the given identifier in theUIStoryboard
identified bystoryboardIdentifierForViewControllerIdentifier(_:)
.