DMInject 0.1.3

DMInject 0.1.3

Narlei Moreira 维护。



DMInject 0.1.3

DMInject

Version License Platform

DMInject 是一个依赖管理器,它可以帮您清理代码并提高工作效率。

示例

要运行示例项目,请克隆仓库,然后首先从 Example 目录运行 pod install

如何使用

第一步 - 添加映射

import DMInject

class DMInjectionMapper: DMInjectionMapperProtocol {
    var arrayReturn = [Any]()

    // Use this map to add the objects, the DMInject will get by type
    func initialize() {
        arrayReturn.append(MyClass())
    }

    func getAllInjections() -> [Any] {
        return arrayReturn
    }
}

添加到您的 AppDelegate

DMInject.main.initialize(mapper: DMInjectionMapper())

现在仅使用

// Exemple 1: Easy way
var myclass: MyClassProtocol?
myclass << DMInject()
if let name = myclass?.getName() {
    print(name)
}


// Exemple 2: Declarative way
let myClass2 = DMInject.main.getInstance(interface: MyClassProtocol.self)
if let name = myClass2?.getName() {
    print(name)
}

// Example 3: Using Property Wraper
@Inject
var myClassX: MyClassProtocol?

要求

  • iOS 9.3
  • XCode 11

安装

DMInject 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中。

pod 'DMInject'

作者

Narlei Moreira, [email protected]

许可

DMInject 在 MIT 许可下提供。更多信息请参阅 LICENSE 文件。