断言

作者: fordring2008 | 来源:发表于2017-02-05 12:31 被阅读6次

    // 断言

    // 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)

    相关文章

      网友评论

          本文标题:断言

          本文链接:https://www.haomeiwen.com/subject/xmfeittx.html