Last active
February 13, 2020 22:14
-
-
Save wilmtang/4ab7f968b6fdddae34c088fa84e29271 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| struct Resource<T> { | |
| let url: URL | |
| // Other properties and methods | |
| } | |
| class NetworkManager { | |
| func load<T>(resource: Resource<T>, withCompletion completion: @escaping (T?) -> Void) { | |
| let session = URLSession(configuration: .ephemeral, delegate: nil, delegateQueue: .main) | |
| let task = session.dataTask(with: resource.url, completionHandler: { (data: Data?, response: URLResponse?, error: Error?) -> Void in | |
| guard let data = data else { | |
| completion(nil) | |
| return | |
| } | |
| // Use the Resource struct to parse data | |
| }) | |
| task.resume() | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment