Created
September 11, 2017 01:39
-
-
Save leovolving/f4e9586506c61941410bca83e5900f24 to your computer and use it in GitHub Desktop.
GET Request Using Swift
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
//A basic GET request using the Ron Swanson Quote API | |
// https://github.com/jamesseanwright/ron-swanson-quotes | |
let targetUrl = URL(string: "http://ron-swanson-quotes.herokuapp.com/v2/quotes") | |
let task = URLSession.shared.dataTask(with: targetUrl!) { (data, response, error) in | |
if error != nil { | |
print("ERROR!") | |
} | |
else { | |
if let content = data { | |
do { | |
let myData = try JSONSerialization.jsonObject(with: content, options: JSONSerialization.ReadingOptions.mutableContainers) as AnyObject | |
print(myData) | |
} | |
catch { | |
print("ERROR.") | |
} | |
} | |
} | |
} | |
task.resume() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment