Last active
July 8, 2019 09:07
-
-
Save ozgurshn/63a59f4d241194bf6a685a3c43f7c8de to your computer and use it in GitHub Desktop.
Networking Request in Xcode 8.0 Playground.
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
import UIKit | |
import PlaygroundSupport | |
PlaygroundPage.current.needsIndefiniteExecution = true | |
let url = URL(string: "http://ip.jsontest.com/")! | |
let session = URLSession.shared() | |
let q = session.dataTask(with: url) { data, response, error in | |
do { | |
if let d = data, let dictionary = try JSONSerialization.jsonObject(with: d, options: []) as? [String: AnyObject] { | |
print(dictionary["ip"]!) | |
} | |
} | |
catch { | |
print("Error \(error)") | |
} | |
} | |
q.resume() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This works for me in Xcode 9 Playgrounds by changing
let session = URLSession.shared()
to
let session = URLSession.shared