- JSON - web api formatted data the is the most popular way of serving downloaded or uploaded content from a network resource
{ "language": "swift", "releaseYear": 2014, "url": "https://developer.apple.com/swift/images/swift-og.png" }
- Codable (Decodable, Encodable) - introduced in Swift 4.2 this protocol allows us to convert JSON into Swift objects quite easily compared to its predecessor JSONSerialization
struct ProgrammingLanguage: Codable { let language: String let releaseYear: Int let url: String }
- JSONDecoder() - class that converts JSON data to a swift object. The swift object must conform to the Codable protocol.
let headlinesData = try JSONDecoder().decode(HeadlinesData.self, from: data)
- URL - a path to a local or network resource
URL(string: urlStirng)
- URLSession - class used to initiate a network request for a resource, used to upload or download web content
let dataTask = URLSession.shared.dataTask(with: url) { (data, response, error) in // code here } dataTask.resume()
- Result type - an enum that is used in a completion handler when making a network request. The enum cases are success and failure.
(Result<UIImage?, Error>) -> ()
- Grand Central Dispatch (GCD) - the concurrency API in Swift. Concurrency is the act of many things happening simultaneously. e.g in iOS that would be allowing a table view to be scrolled without interruption to the user of the application while images are being fetched from the network.
DispatchQueue.main.async { // UI updates go here self.headlineImageView.image = image }
- Escaping Closures - a completion handler needs to be marked @escaping due to the fact that the function returns before the closure value is set from typically an asychronous call (example a background task from fetching a network resource)
completion: @escaping (Result<UIImage?, Error>) -> ()
- Capture list - [weak self] or [unowned self] - used to break retain cycles. Having a retain cycle leads to memory leaks and eventual crashes in our applications.
{ [unowned self] (result) in // code }
- RESTFul API - uses http methods e.g POST, GET, PUT, DELETE to communicate with a web API (Application Programming Interface). Below is an example of an endpoint from the itunes search RESTFul API performing a GET request to retrieve podcast with the term being "swift"
GET https://itunes.apple.com/search?media=podcast&limit=200&term=swift
...more to come