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.
Data
Data — images, text, video, or any media that can be used by our apps.
Protocol
Protocol — a way of communicating; standard operating procedure; the rules for communication
HTTP
HTTP (Hypertext Transfer Protocol) — a protocol or “handshake” that defines how messages (and data) are sent and received by computers; the underlying protocol for the World Wide We
Client
Client — a computer that requests data (or services) from a server
Server
Server — a computer that provides data (or services) to a client upon request
HTTP request
HTTP request — a request for data (or a resource) that a client makes to a server; there are various types of HTTP requests called “HTTP methods”
URL
URL (Uniform Resource Locator) — specifies the location for retrieving data over the web; can be thought of as the name of a file on the World Wide Web, because it usually refers to a file on some machine on the network
HTTP method
HTTP method — specifies the type of HTTP request that is being made; in this course, we will also called these (HTTP) request types
HTTP status code
HTTP status code — a number returned in response to an HTTP request which indicates the result of the request; you may also hear these referred to as “response codes” or “status messages”; here is a nice listing of different HTTP status codes
HTTP GET request
HTTP GET request — a type of HTTP request where a client requests a specified resource from a server
Completion handler
Completion handler — a block of code that is executed after something completes like a network task
HTTPS
HTTPS — a protocol built on top of HTTP that ensures data sent over the network is encrypted, or concealed, from unauthorized access
ATS
ATS (App Transport Security) — Apple’s set of security standards for ensuring our apps keep users’ data safe
Singleton
Singleton — a special kind of object that can only be instantiated once
URL
URL — represents a URL
URLSession — manages network requests for our app
URLSession — manages network requests for our app
URLSessionConfiguration
URLSessionConfiguration — specify settings (ex. timeout interval) for a NSURLSession
URLSessionTask
URLSessionTask — a network task that can be executed
URLSessionDataTask
URLSessionDataTask — subclass of NSURLSessionTask; downloads data directly into memory
URLSessionDownloadTask
URLSessionDownloadTask — subclass of NSURLSessionTask; downloads data to a temporary file
URLSessionUploadTask
URLSessionUploadTask — subclass of NSURLSessionTask; specialized for uploading data
Data
Data — represents data as raw bytes
URLResponse
URLResponse — a container for information about the response to a network request such its status code
Error
Error — a container for information about an error condition