     var credential: URLCredential?
     var completionHandler: ((Data?, URLResponse?, NSError?) -> Swift.Void)?
     var response:URLResponse?
-    var data:Data?
+    var data:Data = Data()
     var dataTask: URLSessionDataTask?
     var error: NSError?
     

    public func urlSession(_ session: URLSession, dataTask: URLSessionDataTask, didReceive response: URLResponse, completionHandler: (URLSession.ResponseDisposition) -> Swift.Void){
        self.dataTask = dataTask
        self.response = response
        session.configuration.urlCache?.getCachedResponse(for: dataTask, completionHandler: { [weak self](cachedURLResponse) in
            if cachedURLResponse != nil{
                self?.data = cachedURLResponse?.data
                self?.response = cachedURLResponse?.response
                completionHandler(URLSession.ResponseDisposition.cancel)
            }else{
                self?.data = Data()
                completionHandler(URLSession.ResponseDisposition.allow)
            }
        })
        
    }
    

    }
    
    public func urlSession(_ session: URLSession, dataTask: URLSessionDataTask, didReceive data: Data){
        self.data += data
    }
}
 
