Slide 14
Slide 14 text
For example,
func half(of i: Int) throws -> Int {
assert(i.isMultiple(of: 2))
if !i.isMultiple(of: 2) { throw Error.isOdd }
return i / 2
}
• Precondition:
• accepts Int.
• accepts Even. (not describable as type)
• Postcondition: returns Int.
• Exception: thrown if the argument is odd.
14