Giter Club home page Giter Club logo

swift-ioc-container's Introduction

swift-ioc-container

Actions Status Actions Status

import Swift_IoC_Container

protocol SuperAwesomeBot {
    func saySomething()
}

class StarWarsBot: SuperAwesomeBot {
    func saySomething() {
        print("The Force will be with you. Always.")
    }
}

And use it like this:

// only needed once
IoC.shared.registerLazySingleton(SuperAwesomeBot.self, { StarWarsBot() }) 


let myBot: SuperAwesomeBot = try! IoC.shared.resolve()
myBot.saySomething()

If you are using Swift 5.1 or newer, you could take advantage of the new property wrapper feature. It's already implemented in this library.

There is no more need to initialize the property manually in the initializer. Just declare the property with the expected protocol type.

@Injected private var myBot: SuperAwesomeBot

After declaring the property as @Injected you can access the previously registered object as you are used to.

An example implementation can be found in Example.swift

Requirements

There are no further requirements beside Swift 5.1, just copy this little lib in your project and start.

Installation

swift_ioc_container is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'Swift-IOC-Container'

Updating

  1. First, do your changes :)
  2. Update PodSpec with a new version number
  3. Push and create a new tag with the same version number
  4. Execute the following line to update PodSpec on CocoaPods.org
pod trunk push Swift-IOC-Container.podspec

Note:

You need to be an owner of course.

  • Create your account like this:
pod trunk register [email protected] "Mein Name" --description="Name meines Rechners"
  • An owner needs to add you as owner:
pod trunk add-owner Swift-IOC-Container [email protected]

Troubleshooting:

Error with .netRc:

chmod 0600 ~/.netrc

Authors

Michael Scherbakow, [email protected]
Jonas Österle, [email protected]
Pascal Friedrich, [email protected]
Philipp Manstein, [email protected]

License

Swift_IoC_Container is available under the MIT license. See the LICENSE file for more info.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.