Unit Testing Dispatch Queues With Dependency Injection

September 30, 2018 | Swift, Networking, Unit Testing, iOS, macOS, tvOS, watchOS

We write asynchronous code when we know a task will take time to complete, whether because it's computationally expensive or we're making a network request. Testing this code can be difficult, especially when the asynchronous logic is internal. For example, let's say we're making a fire and forget request to load an image into an image view? We would likely make the request on a background queue and . . .

Downloading, Caching & Decoding Images Asynchronously with Alamofire: Part 2 (Swift 4)

August 11, 2018 | Swift, Alamofire, Networking, iOS, macOS

In Part 1 of this tutorial, I explained how to use the Alamofire and AlamofireImage libraries to asynchronously download and cache images to be displayed in a UICollectionView. At the end of that project, we still had a performance problem. UIImage by default waits until right before display to decode . . .

Downloading, Caching & Decoding Images Asynchronously with Alamofire: Part 1 (Swift 4)

August 11, 2018 | Swift, Alamofire, Networking, iOS, macOS

Downloading and caching images are common tasks in iOS development, especially when using collection and table views. In this tutorial, we're going to use the popular Swift networking library Alamofire and its companion image library AlamofireImage to build an app that displays images of Glacier National Park.

Using URLSession & Codable Together

January 23, 2018 | Swift, Networking, iOS, macOS, tvOS, watchOS

Almost every app we write needs to retrieve and serialize data from an API. Networking and serialization are not easy problems to solve, which is why open-source frameworks like Alamofire, Moya, and SwiftyJSON have been written to simplify this task. However, using URLSession and the new Codable protocol introduced in Swift 4 . . .

Downloading, Caching & Decoding Images Asynchronously with Alamofire: Part 2

December 18, 2016 | Swift, Alamofire, Networking, iOS, macOS

In Part 1 of this tutorial, I explained how to use the Alamofire and AlamofireImage libraries to asynchronously download and cache images to be displayed in a UICollectionView. At the end of that project, we still had a performance problem. UIImage by default waits until right before display to decode . . .