Created
September 29, 2018 05:06
-
-
Save Muneefm/abceaf994885070ab2f419fbf58018dc to your computer and use it in GitHub Desktop.
This file contains 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 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