April 2015
Intermediate to advanced
556 pages
17h 47m
English
When writing tests, it can often at first seem more convenient to use literals (such as "tomato" and 54). For example, rather than creating separate variables for each of the arguments, it may at first seem easier to write the following:
let course = Course(title: "Name",
url: NSURL(string: "http://bignerdranch.com/")!,
nextStartDate: NSDate())
The problem with this approach, of course, is that you have to use another literal later on when you want to use the value again:
XCTAssertEqual(course.title, "Name")
This is a problem because there is no automated checking that you used the same literal every time. When you use a constant, by contrast, the compiler will complain if you misspell its name. ...