Adding a coordinate property

To drive the addition of a coordinate property, we need a failing test. Add the following test to LocationTests:

func test_Init_SetsCoordinate() { 
  let coordinate =     CLLocationCoordinate2D(latitude: 1,                           longitude: 2) 

  let location = Location(name: "",                           coordinate: coordinate) 

  XCTAssertEqual(location.coordinate?.latitude,                   coordinate.latitude)  XCTAssertEqual(location.coordinate?.longitude,                 coordinate.longitude) 

First, we create a coordinate and use it to create an instance of Location. Then, we assert that the latitude and longitude of the location coordinates are set to the correct values. We use the values 1 and 2 in the initializer of CLLocationCoordinate2D, because it also has an initializer that takes no arguments ...

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.