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



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) { = data
      self.urlResponse = urlResponse
      self.responseError = responseError
 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 :


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

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

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