 
 import UIKit
 
-class SuperMockURLProtocol: NSURLProtocol {
+class SuperMockURLProtocol: URLProtocol {
     
-    override class func canInitWithRequest(request: NSURLRequest) -> Bool {
+    override class func canInit(with request: URLRequest) -> Bool {
         
         if request.hasMock() {
-            print("Requesting MOCK for : \(request.URL)")
+            print("Requesting MOCK for : \(String(describing: request.url))")
             return true
         }
-        print("Passing Through WITHOUT MOCK : \(request.URL)")
+        print("Passing Through WITHOUT MOCK : \(String(describing: request.url))")
         return false
     }
     
     
-    override class func canonicalRequestForRequest(request: NSURLRequest) -> NSURLRequest {
+    override class func canonicalRequest(for request: URLRequest) -> URLRequest {
         return request
     }
 

    }
}

class SuperMockRecordingURLProtocol: NSURLProtocol {
    
    var connection : NSURLConnection?
    var mutableData : NSMutableData?
    
    override class func canInitWithRequest(request: NSURLRequest) -> Bool {
        
        if let _ = NSURLProtocol.propertyForKey("SuperMockRecordingURLProtocol", inRequest: request) {
            return false
        }
        if SuperMockResponseHelper.sharedHelper.recording  {

        let mockedRequest = SuperMockResponseHelper.sharedHelper.mockRequest(request)
        if let mockData = SuperMockResponseHelper.sharedHelper.responseForMockRequest(mockedRequest) {
   
            let mimeType = SuperMockResponseHelper.sharedHelper.mimeType(mockedRequest.url!)
            var response = URLResponse(url: mockedRequest.url!, mimeType: mimeType, expectedContentLength: mockData.count, textEncodingName: "utf8")
            if let mockResponse = SuperMockResponseHelper.sharedHelper.mockResponse(request) {
                response = mockResponse
            }
            
            client?.urlProtocol(self, didReceive: response, cacheStoragePolicy: .notAllowed)
            client?.urlProtocol(self, didLoad: mockData)
            client?.urlProtocolDidFinishLoading(self)
        }
    }
    
