Skip to content

Instantly share code, notes, and snippets.

@lfarah
Created July 5, 2016 02:38
Show Gist options
  • Save lfarah/91e1b1f9aa7bff3642a051d9031e3d5c to your computer and use it in GitHub Desktop.
Save lfarah/91e1b1f9aa7bff3642a051d9031e3d5c to your computer and use it in GitHub Desktop.
let urlPath: String = "http://api.giphy.com/v1/gifs/search?q=funny+cat&api_key=dc6zaTOxFJmzC&limit=1"
let url: URL = URL(string: urlPath)!
var request1: URLRequest = URLRequest(url: url)
request1.httpMethod = "GET"
request1.timeoutInterval = 60
let session = URLSession.shared()
// do {
/*try*/
let task = session.dataTask(with: request1) { (data, response, error) in
do {
print(error?.description)
if let jsonResult = try JSONSerialization.jsonObject(with: data!, options: JSONSerialization.ReadingOptions.mutableContainers) as? [String: AnyObject] {
print("ASynchronous\(jsonResult)")
}
} catch {
print("error")
}
}
task.resume()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment