Type-safe and constructor injectable InterfaceBuilder protocols.
Branch: master
Clone or download
tarunon Merge pull request #34 from sgr-ksmt/patch-1
fixed InstantiateStandard's dependency version.
Latest commit 7f5fd67 Oct 30, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
Instantiate.playground update xcode project Oct 3, 2017
Instantiate.xcodeproj Fix typo Nov 4, 2017
Sources Fix typo Nov 4, 2017
Tests remove under swift 3.x support Oct 13, 2017
.gitignore regenerate xcodeproj using spm Jun 10, 2017
.swift-version update .swift-version Oct 3, 2017
.travis.yml change swift version Sep 16, 2017
Instantiate.podspec fixed InstantiateStandard's dependency version. Aug 29, 2018
InstantiateStandard.podspec fixed InstantiateStandard's dependency version. Aug 29, 2018
LICENSE
Package.swift support mac os Jun 13, 2017
Readme.md Update Readme.md Sep 17, 2017

Readme.md

Instantiate

Build Status Carthage compatible

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

to be

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

Protocols

StoryboardInstantiatable

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

NibInstantiatableWrapper

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

Reusable

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'

Requirement

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

for Swift3.x

Version 2 support swift3.