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 
    self.itemDescription = itemDescription 
    self.timestamp = timestamp 
  } 
} 

Run the tests. All the tests pass. The tests are green and there is nothing to refactor.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.226.165.247