Adding an itemDescription property

A to-do item can have a description. We would like to have an initializer that also takes a description string. To drive the implementation, we need a failing test for the existence of this initializer:

func test_Init_TakesTitleAndDescription() { 
  _ = ToDoItem(title: "Foo",                itemDescription: "Bar") 
} 

Again, this code does not compile because there is Extra argument 'itemDescription' in call. To make this test pass, we add an itemDescription property of type String? to ToDoItem:

struct ToDoItem { 
  let title: String 
  let itemDescription: String? 
} 

Run the tests. The test_Init_TakesTitle() test fails (that is, it does not compile) because there is Missing argument for parameter 'itemDescription' in the call. ...

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.