Last active
May 5, 2021 15:34
-
-
Save david8lumen/62d75f9fad6c63226ebc461dfc584c89 to your computer and use it in GitHub Desktop.
iOS HTTP Request
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 application(_ application: UIApplication, | |
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { | |
var components = URLComponents() | |
components.scheme = "http" | |
components.host = "192.168.1.53" | |
components.port = 8000 | |
components.path = "/teachers.json" | |
// Which finally brings us http://192.168.1.53:8000/teachers.json | |
if let url = components.url { | |
URLSession.shared.dataTask(with: url) { data, response, error in | |
if let error = error { | |
print(error) | |
} else if let data = data, | |
let jsonResponse = try? JSONSerialization.jsonObject(with: data, | |
options: .allowFragments) { | |
print(jsonResponse) | |
} | |
}.resume() | |
} | |
return true | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment