Udacity Networking in iOS and Swift Flashcards
What is a singleton?
A singleton is an special kind of object that can only be instantiated once. So if you use the shared URLSession in this file, and then in a another file you use the shared URL session, you’re actually still referring to the same object in both files, becuase it’s a singleton there can only be one.
What is a completion handler?
A completion handler is a block of code that is executed after something completes like a network task
What is ATS?
App Transport Security - ATS
Apple’s set of security standards for ensuring our apps keep users’ data safe.
What is URL in Swift?
URL represents a URL
What is URLSession ?
URLSession manages network requests for our app
What is URLSessionConfiguration ?
URLSessionConfiguration specifies settings (eg timeout interval) for a NSURLSession (or URLSession?)
What is URLSessionTask ?
URLSessionTask is a network task that can be executed
What is URLSessionDataTask ?
URLSessionDataTask is a subclass of NSURLSessionTask; it downloads data directly into memory
What is URLSessionDownloadTask ?
URLSessionDownloadTask is a subclass of NSURLSessionTask; it downloads data temporary file
What is URLSessionUploadTask ?
URLSessionUploadTask is a subclass of NSURLSessionTask; it is specialsed for uploading data
What is URLResponse ?
URLResponse is a container for information about the response to a network request such its status code
What is Error ?
Error is a container for information about an error condition
What are the steps for getting JSON data and parsing it?
- Get the raw JSON data.
- Parse the JSON data into a foundation object, like an NS dictionary, or an NSArray.
- Grab the data from the Foundation object.
Describe deserialising JSON?
- get photos dictionary at the “photos” key
- in the photos dictionary, get the array of the photo dictionaries at the “photo” key
- print the first photo dictionary
if let photosDictionary = parsedResult[Constants.FlickrResponseKeys.Photos] as? [String:AnyObject], let photoArray = photosDictionary[Constants.FlickrResponseKeys.Photo] as? [[String:AnyObject]] { print(photoArray[0])
In terms of URLComponents, break down the structure of a web address and building it
Note we do this because the URLComponents class ensure that all characters are escaped and URL contains only safe ascii characters
The URL: https://api.flickr.com/services/rest? method=flickr.photos.search& api_key=980958230459843086554& text=purple
First line: :// / (to ?)
everything after the ? is the query
They consist of name: value pairs that a server uses to determine its response -
eg
text=purple
method=method=flickr.photos.search&
These are name=value. Each pair is separated by an &
To add the query line (eg after the ? to the end), we need to add a URLQueryItem (see below), add the key : value pairs, and then append them to the component var (aka the URL)
var components = URLComponents()
components. scheme = “https”
components. host = “api.flickr.com”
components. path = “/services/rest”
components. queryItems = URLQueryItem
let queryItem1 = URLQueryItem(name: "method", value: "flickr.photos.search") let queryItem2 = URLQueryItem(name: "api_key", value: "1234") let queryItem3 = URLQueryItem(name: "text", value: "purple")
components. queryItems!.append(queryItem1)
components. queryItems!.append(queryItem2)
components. queryItems!.append(queryItem3)
print(components.url!)
Network
Network — the system of interconnected computer networks from which we can access data.