Swift 可選綁定

來源:互聯網
上載者:User

標籤:

if let actualNumber = possibleNumber.toInt(){ //如果possibleNumber.toInt是一個整形賦值給actualNumber,並列印 true 分支
  println("\(possibleNumber) has an integer value of \(actualNumber)")
 } else {  println("\(possibleNumber) could not be converted to an integer") }
  ==============================================可選暗示了常量或者變數可以“沒有值”。可選可以通過 if 語句來判斷是否有值,如果有值的話可以通過可選綁定來解析值。

Swift 可選綁定

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.