Swiftpack.co - tarunon/Instantiate as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by tarunon.
tarunon/Instantiate 4.0.1
Type-safe and constructor injectable InterfaceBuilder protocols.
⭐️ 155
🕓 1 year ago
iOS macOS tvOS
.package(url: "https://github.com/tarunon/Instantiate.git", from: "4.0.1")


Build Status Carthage compatible

Type-safe and constructor injectable InterfaceBuilder protocols.


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])

to be

import Instantiate
import InstantiateStandard
extension ViewController: StoryboardInstantiatable {}
let vc = ViewController(with: [1, 2, 3])



Supports using viewController with Storyboard. Implement StoryboardInstantiatable at your viewController class, then you can use ViewController(with: Dependency).


Supports using view with Nib. Implement NibInstantiatable at your view class, then you can use View(with: Dependency).


Supports using view implements NibInstantiatable in other InterfaceBuilder. NibInstantiatableWrapper supports workaround. Make new UIView subclass, and implement NibInstantiatableWrapper, call loadView on init(coder:) and prepareForInterfaceBuilder. http://stackoverflow.com/questions/27807951/how-to-embed-a-custom-view-xib-in-a-storyboard-scene


Supports UITableViewCell / UICollectionViewCell reuse features. Implement Reusable, then you can dequeue cell using Cell.dequeue(from: Parent, for: IndexPath, with: Dependency).


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.



github "tarunon/Instantiate"


pod 'Instantiate'

Swift Package Manager

Select Xcode menu File > Swift Packages > Add Package Dependency... and enter repository URL with GUI.

Repository: https://github.com/tarunon/tarunon/Instantiate


Platform Version
iOS 9.0+
macOS 10.11+
tvOS 9.0+
Swift 4.0+


Stars: 155
Last commit: 1 year ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

1 year ago

Fix spm package resolve issue #41

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics