断言
2017-02-05 本文已影响6人
fordring2008
// 断言
// assert(<#T##condition: Bool##Bool#>, <#T##message: String##String#>)
// 断言在debug期间才会执行,编译期间不会打包进去
private let absoluteZeroInCelsius = -172.0
func convetToKelvin(_ celsius: Double) -> Double {
assert(celsius > absoluteZeroInCelsius, "输入的摄氏温度不能低于决定零度")
return celsius - absoluteZeroInCelsius
}
let roomTeperature = convetToKelvin(27)
// 编译就报错了,
let tooCold = convetToKelvin(-300)