Skip to content

Instantly share code, notes, and snippets.

@azamsharp
Created November 27, 2017 20:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save azamsharp/2b833397e7c71f86e84dcfd49ff8662c to your computer and use it in GitHub Desktop.
Save azamsharp/2b833397e7c71f86e84dcfd49ff8662c to your computer and use it in GitHub Desktop.
Webservice loadSources Function
func loadSources(completion :@escaping ([Source]) -> ()) {
URLSession.shared.dataTask(with: sourcesURL) { data, _, _ in
if let data = data {
let json = try! JSONSerialization.jsonObject(with: data, options: [])
let sourceDictionary = json as! JSONDictionary
let dictionaries = sourceDictionary["sources"] as! [JSONDictionary]
let sources = dictionaries.flatMap(Source.init)
DispatchQueue.main.async {
completion(sources)
}
}
}.resume()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment