V8tr / SwiftCombineNetworking

Promise-Based Networking in Swift 5 with URLSession, Combine and Codable
https://www.vadimbulavin.com/
79 stars 17 forks source link

could not make it work #2

Closed workingDog closed 4 years ago

workingDog commented 4 years ago

I could not make this work at all. I keep getting this error:

finished with error [-999] Error Domain=NSURLErrorDomain Code=-999 "cancelled" UserInfo={NSErrorFailingURLStringKey=https://api.github.com/users/..../repos, NSLocalizedDescription=cancelled, NSErrorFailingURLKey=https://api.github.com/users/..../repos}

mgcrea commented 4 years ago

Looks like a duplicate of #1.

V8tr commented 4 years ago

Hi @workingDog, I think you are not retaining the subscription. For the purpose of example, I enforce its lifetime like this https://github.com/V8tr/SwiftCombineNetworking/blob/master/CombineNetworkLayer/main.swift#L27.

V8tr commented 4 years ago

@mgcrea thanks for pointing out, it also looks like a duplicate of #1 to me.

mgcrea commented 4 years ago

You can also use .store(in: &subscriptions) after a sink() with var subscriptions = Set<AnyCancellable>() to retain the cancellable.