Asynchronous Testing

Writing concurrent code has many pitfalls and because of the inherit complexity, testing that code may also prove difficult. By leveraging XCTest, the test cases default to synchronous tests (i.e. when the test hits the last line in scope, it ends). Now, some developers may try to solve this by adding sleeps or manipulating the run loop, but those methods are unreliable or can cause side effects. To properly handle parallel scenarios, XCTest provides an API that allows you to create expectations for the outcome of an asynchronous operation by adhering to the XCTWaiterDelegate protocol....

Parallelizing Work with GCD

In order to increase performance of your application or framework, it behooves you to parallelize your work if possible. By batching together groups of similar work, you can take advantage of multi-core systems to increase the responsiveness and throughput of your code. Good candidates for parallelization are network downloads, resource fetching and loading, and computationally heavy calculations. To accomplish this, GCD provides a few built-in options and you can also use some of its primitives to create more sophisticated synchronization tools....

Protecting Critical Sections

When working on an application or framework, you eventually run into the problem of needing to do some work in a controlled environment. In order to guarantee the safety of the work being done, you want to lock down that particular path so that it can execute without state changing while it is running. This is what’s called a critical section. Luckily, the Apple development platform provides an abundance of options for implementing parallelizable code....