I've been using ReactiveSwift for a few months now but there is a something that I dont fully understand: lifetime objects.
For example, lets say I have a SignalProducer
which will make an API call, this is wrapped on a class:
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)
}
}
}
}
My question is: Is it necessary to use lifetime
on this case?
I understood that lifetime
will retain the service call so it has something when it return but since this is also wrapped on ServiceWrapped
I don't think using lifetime
is really necessary.
Thanks in advance.