Please enable JavaScript.
Coggle requires JavaScript to display documents.
Building a weather app (JSONDownloader (fun jsonTask (Two jobs to do:…
Building a weather app
-
CurrentWeather
-
extension CurrentWeather
A initialiser:
As the JSON data received from the server is formatted in String,
In the extension, they are converted into Double or String types as supposed to display
-
-
Coordinate
Class Coordinate
This class has member properties, "latitude", and "longitude" to locate the user.
extension Coordinate
A computed property "description" to return both latitude and longitude at once.
-
DarkSkyAPIClient
This class is to interact with the Dark Sky API and give you either the current weather in the form of a populated model instance or an error.
-
func getCurrentWeather
-
- Get JSON Data having an instance of JSONDownloader
JSONDownloader
-
-
fun jsonTask
- Takes a URLRequest and returns URLSessionDataTask
- Create a task(URLSessionDataTask)
- Two jobs to do: process the task and then JSONCompletionHandler to evaluate whether this method returns either data or error
Response is to be converted into HTTPURLResponse and then if the status code of the response is 200 and the data received from the server is not nil, JSONSeralisation is to be done next.
-