Injectable
Dependency Injection for Swift.
The dependency injection pattern leads to code that's modular and testable, and Guice makes it easy to write.
Installation
pod 'Injectable'
Usage
// ViewController.swift
class ViewController: UIViewController {
@IBAction func show(_ sender: Any) {
let viewController: InjectableViewController = InjectableViewController(with: .init(color: .green))
self.present(viewController, animated: true, completion: nil)
}
override func viewDidLoad() {
super.viewDidLoad()
}
}// InjectableViewController.swift
protocol Colorable: Injectable {
init(with dependency: Dependency)
}
class InjectableViewController: UIViewController, Colorable {
required init(with dependency: InjectableViewController.Dependency) {
super.init(nibName: nil, bundle: nil)
self.inject(dependency)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
struct Dependency {
var color: UIColor
}
func inject(_ dependency: InjectableViewController.Dependency) {
self.view.backgroundColor = dependency.color
}
}
Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.

