Type-safe and constructor injectable InterfaceBuilder protocols.
Summary
Storyboard and Nib is not type safe, if you use UIStoryboard or UINib, your code would be get some gloom.
Instantiate take type-safe protocols for Storyboard and Nib. Lets’ improve our code with type-safe protocols!
as is
let storyboard = UIStoryboard(name: "ViewController", bundle: Bundle.main)
let vc = storyboard.instantiateInitialViewController() as! ViewController
vc.inject([1, 2, 3])
Supports using viewController with Storyboard. Implement StoryboardInstantiatable at your viewController class, then you can use ViewController(with: Dependency).
NibInstantiatable
Supports using view with Nib. Implement NibInstantiatable at your view class, then you can use View(with: Dependency).
Supports UITableViewCell / UICollectionViewCell reuse features.
Implement Reusable, then you can dequeue cell using Cell.dequeue(from: Parent, for: IndexPath, with: Dependency).
InstantiateStandard
StoryboardType and NibType required static var storyboard or static var nib. You need to write these values on own class, it is troublesome…
Many developer define StoryboardName is same of ClassName, and if you are also, you can use InstantiateStandard.
This libraly add default implementation of StoryboardType, NibType, and Reusable.
Instalation
Carthage
github "tarunon/Instantiate"
Pods
pod 'Instantiate'
Swift Package Manager
Select Xcode menu File > Swift Packages > Add Package Dependency… and enter repository URL with GUI.
Instantiate
Type-safe and constructor injectable InterfaceBuilder protocols.
Summary
Storyboard and Nib is not type safe, if you use
UIStoryboard
orUINib
, your code would be get some gloom. Instantiate take type-safe protocols for Storyboard and Nib. Lets’ improve our code with type-safe protocols!as is
to be
Protocols
StoryboardInstantiatable
Supports using viewController with Storyboard. Implement
StoryboardInstantiatable
at your viewController class, then you can useViewController(with: Dependency)
.NibInstantiatable
Supports using view with Nib. Implement
NibInstantiatable
at your view class, then you can useView(with: Dependency)
.NibInstantiatableWrapper
Supports using view implements NibInstantiatable in other InterfaceBuilder. NibInstantiatableWrapper supports workaround. Make new
UIView
subclass, and implementNibInstantiatableWrapper
, callloadView
oninit(coder:)
andprepareForInterfaceBuilder
. http://stackoverflow.com/questions/27807951/how-to-embed-a-custom-view-xib-in-a-storyboard-sceneReusable
Supports
UITableViewCell
/UICollectionViewCell
reuse features. ImplementReusable
, then you can dequeue cell usingCell.dequeue(from: Parent, for: IndexPath, with: Dependency)
.InstantiateStandard
StoryboardType
andNibType
requiredstatic var storyboard
orstatic var nib
. You need to write these values on own class, it is troublesome… Many developer define StoryboardName is same of ClassName, and if you are also, you can useInstantiateStandard
. This libraly add default implementation ofStoryboardType
,NibType
, andReusable
.Instalation
Carthage
Pods
Swift Package Manager
Select Xcode menu File > Swift Packages > Add Package Dependency… and enter repository URL with GUI.
Requirement