Udacity Networking in iOS and Swift Flashcards Preview

Programming > Udacity Networking in iOS and Swift > Flashcards

Flashcards in Udacity Networking in iOS and Swift Deck (40):
1

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.

2

What is a completion handler?

A completion handler is a block of code that is executed after something completes like a network task

3

What is ATS?

App Transport Security - ATS

Apple's set of security standards for ensuring our apps keep users' data safe.

4

What is URL in Swift?

URL represents a URL

5

What is URLSession ?

URLSession manages network requests for our app

6

What is URLSessionConfiguration ?

URLSessionConfiguration specifies settings (eg timeout interval) for a NSURLSession (or URLSession?)

7

What is URLSessionTask ?

URLSessionTask is a network task that can be executed

8

What is URLSessionDataTask ?

URLSessionDataTask is a subclass of NSURLSessionTask; it downloads data directly into memory

9

What is URLSessionDownloadTask ?

URLSessionDownloadTask is a subclass of NSURLSessionTask; it downloads data temporary file

10

What is URLSessionUploadTask ?

URLSessionUploadTask is a subclass of NSURLSessionTask; it is specialsed for uploading data

11

What is URLResponse ?

URLResponse is a container for information about the response to a network request such its status code

12

What is Error ?

Error is a container for information about an error condition

13

What are the steps for getting JSON data and parsing it?

1. Get the raw JSON data.

2. Parse the JSON data into a foundation object, like an NS dictionary, or an NSArray.

3. Grab the data from the Foundation object.

14

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])

15

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&amp
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!)

16

Network

Network — the system of interconnected computer networks from which we can access data.

17

Data

Data — images, text, video, or any media that can be used by our apps.

18

Protocol

Protocol — a way of communicating; standard operating procedure; the rules for communication

19

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

20

Client

Client — a computer that requests data (or services) from a server

21

Server

Server — a computer that provides data (or services) to a client upon request

22

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”

23

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

24

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

25

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

26

HTTP GET request

HTTP GET request — a type of HTTP request where a client requests a specified resource from a server

27

Completion handler

Completion handler — a block of code that is executed after something completes like a network task

28

HTTPS

HTTPS — a protocol built on top of HTTP that ensures data sent over the network is encrypted, or concealed, from unauthorized access

29

ATS

ATS (App Transport Security) — Apple’s set of security standards for ensuring our apps keep users’ data safe

30

Singleton

Singleton — a special kind of object that can only be instantiated once

31

URL

URL — represents a URL

32

URLSession — manages network requests for our app

URLSession — manages network requests for our app

33

URLSessionConfiguration

URLSessionConfiguration — specify settings (ex. timeout interval) for a NSURLSession

34

URLSessionTask

URLSessionTask — a network task that can be executed

35

URLSessionDataTask

URLSessionDataTask — subclass of NSURLSessionTask; downloads data directly into memory

36

URLSessionDownloadTask

URLSessionDownloadTask — subclass of NSURLSessionTask; downloads data to a temporary file

37

URLSessionUploadTask

URLSessionUploadTask — subclass of NSURLSessionTask; specialized for uploading data

38

Data

Data — represents data as raw bytes

39

URLResponse

URLResponse — a container for information about the response to a network request such its status code

40

Error

Error — a container for information about an error condition