Created
January 15, 2019 06:03
-
-
Save yhkaplan/4b0c1cf6febcfb183afeb3eef4754865 to your computer and use it in GitHub Desktop.
Basic explainer resource for beginners
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
import Foundation | |
import PlaygroundSupport | |
// Model | |
struct Character: Decodable { | |
let name: String | |
} | |
// NW | |
let url = URL(string: "https://swapi.co/api/people/1/")! | |
URLSession.shared.dataTask(with: url) { data, res, error in | |
guard | |
let data = data, | |
let string = String(data: data, encoding: .utf8), | |
let character = try? JSONDecoder().decode(Character.self, from: data) | |
else { | |
let errorMessage = error?.localizedDescription ?? "Unknown error" | |
print(errorMessage) | |
return | |
} | |
print(res) | |
// print(string) | |
// print(character) | |
}.resume() | |
// Boring setting for Playgrounds | |
PlaygroundPage.current.needsIndefiniteExecution = true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment