Skip to content

0sw2ld0/swin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Swin

Version License Platform

Swin is a library of service locators to help you use IoC in your projects

Requirements

  • iOS 10.0+ / Mac OS X 10.10+
  • Xcode 12+

Installation

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

platform :ios, '10.0'
use_frameworks!

pod 'Swin'

Use pod install command. For more info of the installation and usage of CocoaPods, CocoaPods website.

Usage

Our class or struct

We created the next Animal protocol:

protocol Animal {
    var name: String {get set}
    func say() -> String
}

After that we have the Dog struct:

struct Dog: Animal {
    var name: String
    
    init(name: String) {
        self.name = name
    }
    
    func say() -> String {
        "Guau Guau"
    }
}

Also we have the cat struct:

struct Cat: Animal {
    var name: String
    
    init(name: String) {
        self.name = name
    }
    
    func say() -> String {
        "Miau Miau"
    }
}

Then we have the struct PetOwner, we assign the values inside in PetOwner using the annotation @Inject

struct PetOwner {
    @Inject var dog: Animal
    @Inject var cat: Cat
}

Creating the modules

We created the demoModule Module:

let demoModule = module { container in
	container.factory { Dog(name: "Fido") as Animal}
	container.factory { Cat(name: "Tiger")}
}

Start Swin

We in the AppDelegate let's star Swin

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
	Swin.modules(demoModule)
	Swin.start()
   /* some code */
   return true
}

Author

Oswaldo Leon, oswaldo.leon9@gmail.com

License

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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published