Adding a timestamp property

A ToDoItem can also have a due date represented by a timestamp. Add the following test to make sure we can initialize an instance of ToDoItem with timestamp:

func test_Init_SetsTimestamp() { 
  let item = ToDoItem(title: "",                       timestamp: 0.0)   XCTAssertEqual(item.timestamp, 0.0,                  "should set timestamp") 
} 

Again, this test does not compile because there is an extra argument in the initializer. From the implementation of the other properties, we know that we have to add a timestamp property in ToDoItem and set it in the initializer:

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

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.