venmo / DVR

Network testing for Swift
http://blog.soff.es/network-testing-in-swift-with-dvr
MIT License
651 stars 86 forks source link

Fix "[Session defaultTaskGroup]: unrecognized selector sent to instance" for Swift 5.1 (#93) #94

Closed m-herold closed 4 years ago

m-herold commented 4 years ago

Fix dataTask with URL for Swift 5.1 (#93 ).

dmiluski commented 4 years ago

Hi @m-herold , thanks for filing an issue as wells as a request.

So I understand better: ‘Fix "[Session defaultTaskGroup]: unrecognized selector sent to instance" for Swift 5.1‘

Does this issue have something to do with Swift 5.1? If not Swift 5.1 specific, could you help me find what is calling this method with a URL instead of URLRequest?

m-herold commented 4 years ago

Calling the dataTask with an URL instead of a URLRequest is a valid method call according to Apple's documentation of the URLSession interface: https://developer.apple.com/documentation/foundation/urlsession/1411554-datatask

Same applies of course for calling it with an URL and a completionHandler: https://developer.apple.com/documentation/foundation/urlsession/1410330-datatask

It seems that prior to Swift 5.1 these methods have internally wrapped the URL in a URLRequest and forwarded the call to the according URLRequest-methods (https://developer.apple.com/documentation/foundation/urlsession/1410592-datatask). This worked fine with DVR since these methods have been overridden in the Session. This does not seem to occur anymore with Swift 5.1 which is causing the mentioned NSInvalidArgumentException.

dmiluski commented 4 years ago

Although tagged, and released for consumption by Carthage, I'm running into an issue publishing the cocoapod due to: https://github.com/CocoaPods/CocoaPods/issues/9176

Will publish once resolved.