Latest 1.0
Homepage https://github.com/1amageek/Injectable
License MIT
Platforms ios 8.0, osx 10.10, watchos 3.0, tvos 9.0
Authors
Injectable

[![Version](http://img.shields.io/cocoapods/v/Injectable.svg)](http://cocoapods.org/?q=Injectable)
[![Platform](http://img.shields.io/cocoapods/p/Injectable.svg)](http://cocoapods.org/?q=Injectable)
[![Downloads](https://img.shields.io/cocoapods/dt/Injectable.svg?label=Total%20Downloads&colorB=28B9FE)](https://cocoapods.org/pods/Injectable)

Dependency Injection for Swift.

The dependency injection pattern leads to code that’s modular and testable, and Guice makes it easy to write.

Google Guice

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
    }
}

Latest podspec

{
    "name": "Injectable",
    "version": "1.0",
    "summary": "Swift Dependency Injection",
    "description": "Dependency Injection.nThe dependency injection pattern leads to code that's modular and testable, and Guice makes it easy to writenhttps://github.com/google/guice/wiki/Motivation",
    "homepage": "https://github.com/1amageek/Injectable",
    "license": {
        "type": "MIT",
        "file": "./LICENSE"
    },
    "authors": {
        "1amageek": "[email protected]"
    },
    "social_media_url": "http://twitter.com/1amageek",
    "platforms": {
        "ios": "8.0",
        "osx": "10.10",
        "watchos": "3.0",
        "tvos": "9.0"
    },
    "source": {
        "git": "https://github.com/1amageek/Injectable.git",
        "tag": "1.0"
    },
    "source_files": "Injectable/**/*.swift",
    "pushed_with_swift_version": "4.0"
}

Pin It on Pinterest

Share This