Publishing changes with Combine
In today's iOS apps, communication between different parts is often implemented using the Combine framework by Apple. In Combine, data changes are published and can be subscribed to. This design pattern helps to decouple the code and make it easier to maintain.
We will use Combine in our ToDoItemStore
to inform, for example, the table view controller that something changed and the user interface should be updated with the new data.
Open Project Navigator and select the ToDoTests group. Go to the iOS | Source | Unit Test Case option to create a test case class with the name ToDoItemStoreTests
. Import the ToDo
module (@testable import ToDo
) and remove the two test method templates.
Testing asynchronous Combine code
Up to now, all the code we've tested has been synchronous code. Publishing values in Combine is asynchronous. To be able to test Combine code, we need a way to halt the test and wait until the code we want to test is executed...