目录
目录README.md

BasicServiceLocator

Very BasicServiceLocator for Swift

Installation

CocoaPods

pod 'BasicServiceLocator'

Swift Package Manager

Once you have your Swift package set up, adding SwiftyTimber as a dependency is as easy as adding it to the dependencies value of your Package.swift.

dependencies: [
    .package(url: "https://github.com/iballan/BasicServiceLocator.git", .upToNextMajor(from: "0.0.3"))
]

USAGE

// Protocols
protocol ServiceA {}
protocol ServiceB {}

// Implementation
class ServiceAA: ServiceA {}
class ServiceBB: ServiceB {}

// Fake or Debug Implementation
class FakeServiceB: ServiceB{}

// Service Resolver and Container
let serviceLocator : ServiceLocator = BasicServiceLocator()

// Registering
serviceLocator.registerService(ServiceA.self, instance: ServiceAA())
serviceLocator.registerService(ServiceB.self) {
    #if DEBUG
        return FakeServiceB()
    #else
        return ServiceBB()
    #endif
}

// Fetching and using service
let serviceA = try? serviceLocator.getService(ServiceA.self)
let serviceB = try! serviceLocator.getService(ServiceB.self)
关于
36.0 KB
邀请码
    Gitlink(确实开源)
  • 加入我们
  • 官网邮箱:gitlink@ccf.org.cn
  • QQ群
  • QQ群
  • 公众号
  • 公众号

©Copyright 2023 CCF 开源发展委员会
Powered by Trustie& IntelliDE 京ICP备13000930号