Asking for remote information is something very common today. What happens if your playground finished before you receive a server response? In this recipe, we will learn how to deal with this problem
Create a new playground called Chapter 6 Requesting JSONs
, and just in this case, check your internet connection.
To receive JSONs on your playground, follow these steps:
First, we need to locate a URL, which can return more websites. In this case, we will use this URL: https://api.github.com/users/mralexgray/repos.
Create a constant with the URL mentioned earlier:
let url = NSURL(string: "https://api.github.com/users/mralexgray/repos")!
Click on the quick look icon and check that you receive a JSON response.
Now, let's create a request for our URL:
let request = NSURLRequest...