Removing a hidden source of bugs

To be able to use a short initializer only setting the title, we need to define it ourselves. But this also introduces a new source of potential bugs. We can remove the two micro features we have implemented and still have both tests pass. To take a look at how this works, open ToDoItem.swift, and comment out the properties and assignment in the initializer:

struct ToDoItem { 
//  let title: String 
//  let itemDescription: String? 
  init(title: String,        itemDescription: String? = nil) { //    self.title = title 
//    self.itemDescription = itemDescription 

Run the tests. Both tests still pass. The reason for this is that they do not check whether the values of the initializer arguments are actually set to any ToDoItem ...

Get Test-Driven iOS Development with Swift 4 - Third Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.