Last active
December 22, 2019 08:20
-
-
Save piyush23dez/6d835b43a99cd9adbd6eb5a4a98e14f8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typealias CompletionBlock = (Data?) -> Void | |
protocol NetworkService { | |
func make(request: URLRequest, completionHandler: @escaping CompletionBlock) | |
} | |
extension URLSession: NetworkService { | |
func make(request: URLRequest, completionHandler: @escaping CompletionBlock) { | |
let task = self.dataTask(with: request) { data, _, _ in | |
completionHandler(data) | |
} | |
task.resume() | |
} | |
} | |
//create mocked network service | |
class MockedService: NetworkService { | |
func make(request: URLRequest, completionHandler: @escaping CompletionBlock) { | |
completionHandler("Mocked data response".data(using: .utf8)) | |
} | |
} | |
class PilotService: NetworkService { | |
func make(request: URLRequest, completionHandler: @escaping CompletionBlock) {} | |
} | |
class TestService: NetworkService { | |
func make(request: URLRequest, completionHandler: @escaping CompletionBlock) {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment