Created
November 27, 2017 20:11
-
-
Save azamsharp/2b833397e7c71f86e84dcfd49ff8662c to your computer and use it in GitHub Desktop.
Webservice loadSources Function
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
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