我已经使用 ReactiveSwift 几个月了,但是有一个我不完全理解的东西:生命周期对象。
例如,假设我有一个SignalProducer
将进行 API 调用的函数,它包含在一个类中:
class ServiceWrapped {
private let service: Service // the method called on this object returns the SignalProducer
private let (lifetime, token) = Lifetime.make()
// more stuff
func fetchSomething(completion: @escaping (Value?, Error?) -> Void) {
lifetime += service.fetchSomething()
.startWithResult { result in
switch result {
case .success(let value):
completion(value, nil)
case .failure(let error):
completion(nil, error)
}
}
}
}
我的问题是:有必要lifetime
在这种情况下使用吗?
我知道这lifetime
将保留服务调用,因此它在返回时会有一些东西,但由于这也被包裹起来,ServiceWrapped
我认为使用并不是lifetime
真正必要的。
提前致谢。