Skip to content

Instantly share code, notes, and snippets.

@mjhassan
Created September 3, 2019 04:41
Show Gist options
  • Select an option

  • Save mjhassan/1b946a00168ac4c6dbd899826e518c89 to your computer and use it in GitHub Desktop.

Select an option

Save mjhassan/1b946a00168ac4c6dbd899826e518c89 to your computer and use it in GitHub Desktop.
Simple service class template for URLCache example
class APIService: ServiceProtocol {
func get( url: URL, callback: @escaping (_ data: Data?, _ error: Error?) -> Void ) {
let request = URLRequest(url: url, cachePolicy: .returnCacheDataElseLoad, timeoutInterval: 30)
URLSession.shared.dataTask(with: request) { (data, _, error) in
callback(data, error)
}.resume()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment