Skip to content

Instantly share code, notes, and snippets.

@Muneefm
Created September 29, 2018 05:06
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 Muneefm/abceaf994885070ab2f419fbf58018dc to your computer and use it in GitHub Desktop.
Save Muneefm/abceaf994885070ab2f419fbf58018dc to your computer and use it in GitHub Desktop.
func requestData() {
let url = Foundation.URL(string: URL)
let session = URLSession.shared
let task = session.dataTask(with: url!)
{
(data, response, error ) in
do {
let json = try JSONSerialization.jsonObject(with: data!) as! Dictionary<String, AnyObject>
let title = json["original_title"] as! String
let imagePath = json["poster_path"] as! String
// image
do {
let url = Foundation.URL(string: self.imageBaseUrl+imagePath)
let data = try Data(contentsOf: url!)
DispatchQueue.main.async {
self.movieTitle.text = title
self.moviePoster.image = UIImage(data: data)
}
}
catch {
print("error")
}
}
catch {
print("error")
}
}
task.resume()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment