simpleDI 1.1.1

simpleDI 1.1.1

Patrick Täuferptaeufer 维护。



simpleDI 1.1.1

  • Patrick Täufer

simpleDI

一个用于 Swift 框架注入的简单库

安装

要使用 CocoaPods 将 simpleDI 集成到您的 Xcode 项目中,请在 Podfile 中指定它。

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '10.0'
use_frameworks!

target '<Your Target Name>' do
    pod 'simpleDI'
end

然后,运行以下命令。

$ pod install

准备

要开始使用,请将名为 Injector.swift 的文件添加到您的项目中任何位置。

用法

现在您可以在项目中定义不同的模块,这些模块必须扩展 DependencyModule

class AppModule : DependencyModule {
  
  // Singleton
  let o1 = Object1()
  
  // New instance
  func o2() -> Object2() {
    return Object2()
  }
  
  // usage of other dependencies
  let o3 = Object3(o2 : inject())
}

如果您想在某个类中注入依赖项

class ViewController : UIViewController {
  
  private let o1 : Object1 = inject()
  // or
  private let o1 = inject(Object1.self)
  
  ...
}