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 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.