ios – Swift – Subclassing URLSessionDataTask – Which super.init(DataTaskFakeWrapper: URLSessionDataTask ?????????) Apply?

0
45

[ad_1]

I’m trying to subclass a URLSessionDataTask as shown in this post Initializer does not override a designated initializer while subclassing NSURLSession Swift Except that the sub class init imposes a super.init back to the parent class. Here is the code :

class DataTaskFakeWrapper {
 let DataTaskFakeWrapper: URLSessionDataTask
  init(DataTaskFakeWrapper: URLSessionDataTask) {
      self.DataTaskFakeWrapper = DataTaskFakeWrapper
 }

}

class DataTaskFake: DataTaskFakeWrapper {
 var completionHandler: ((Data, URLResponse, Error) -> Void)?
 var data: Data
 var urlResponse: URLResponse
 var responseError: Error
 init( data: Data, urlResponse: URLResponse, responseError: Error) {
      self.data = data
      self.urlResponse = urlResponse
      self.responseError = responseError
      super.init(DataTaskFakeWrapper:
                     URLSessionDataTask)
  }
 
 func resume() {
      completionHandler?(data, urlResponse, responseError)
 }
 
 func cancel() {
      // not applicable
 }

}

The message
“Cannot convert value of type ‘URLSessionDataTask.Type’ to expected argument type ‘URLSessionDataTask” appears and I can’t find the right type to communicate from my sub class :

super.init(DataTaskFakeWrapper:
                     URLSessionDataTask)

and avoid that message : “Cannot convert value of type ‘URLSessionDataTask.Type’ to expected argument type ‘URLSessionDataTask”

With a similar subclassing of URLSession, the super.int allows the URLSession(configuration: .default) argument.

What is the one for URLSessionDataTask in my case. Thanks a lot

[ad_2]