Implementing the ToDoItem struct
To be useful, to-do items need a minimal set of information. In this section, we will create a structure to hold this information while using tests to guide their development.
A to-do app needs a model class/struct to store information for to-do items:
- We will start by adding a new test case to the unit test target. Open the to-do project that we created in the Getting started with Xcode section of Chapter 4, The App We Are Going to Build, and select the ToDoTests group.
- Go to File | New | File..., navigate to iOS | Source | Unit Test Case Class, and click on Next. Put in the name
ToDoItemTests
, make it a subclass ofXCTestCase
, select Swift as the language, and click on Next. - In the next window, click on Create.
- Now, delete the
ToDoTests.swift
template test case.
Adding a title property
A to-do item needs a title
. Follow these steps to add one to our ToDoItem
struct:
- Open
ToDoItemTests.swift
and add the following...