Add the Code to Our Practice App

In real life, we would make a type that communicates with some password changing API. But for our example, we don’t have an actual web service. Instead, we will just print its arguments to the console. To simulate the time it would take to do network communication, it will call either the success closure or the failure closure after 1 second. Additonally, we will be able to alternate between both success and failure so that we are able to try both.

Select the Refactoring group in the Project Navigator and press -N to make a new file. Select Swift File and name it PasswordChanger.swift:

 import​ ​Foundation
 
 final​ ​class​ ​PasswordChanger​ {
 private​ ​ ...

Get iOS Unit Testing by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.