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 . . .

Convenient Sorting With Swift Key Paths

September 30, 2018 | Swift, iOS, macOS, tvOS, watchOS

Key paths were introduced in Swift 4 and allow you to reference a type's properties without evaluating them. In this tutorial, we'll use key paths to write a generic array extension that makes sorting more convenient with code that is easier to read.

Swift Programming For Complete Beginners Part 6: String Interpolation & Type Conversion

September 23, 2018 | Swift, Beginner

In this series we've done a lot of printing to the console. We've printed strings and constants and variables of other types. But it's often useful to be able to insert constants or variables directly into strings, especially when those constants or variables are values of other types. For example, when you want to say "Hello, [name]!" or "The bank account ending in [lastFourDigits] has a balance of [accountBalance]". In the bank account example . . .

Swift Programming For Complete Beginners Part 5: Conditional Logic

September 23, 2018 | Swift, Beginner

A programmer's wife tells him to go to the store and get a loaf of bread. As he's leaving, she says "if they have eggs, get a dozen". The programmer comes back with 12 loaves of bread. A programmer's husband tells her to go to the store and says, "while you're there buy a dozen eggs". She never comes back. Programming is . . .

Swift For Complete Beginners Part 4: Functions

September 22, 2018 | Swift, Beginner

Functions are pieces of code that perform a specific task. A function can also be thought of as a set of instructions packaged together. In Part 1, you used the built-in Swift function `print` to output values to the console. So far you have used it to output "Hello, World!", "Hello, Xcode!", pi, and an email address. When you use a function . . .