Swift語言中的switch語句的妙用

來源:互聯網
上載者:User

標籤:swift   switch   

Swift中的switch語句的類另用法:

// 強大的switch語句var a:Int = 100switch a {case a where a < 0:    println("Negative")case a where a == 0:    println("Zero")case a where a > 0:    println("Positive")default:    println("Unknow")}


這段代碼實現的邏輯是我們平常經常見到的邏輯,但是使用if判斷代碼並不簡潔易於閱讀,不如使用這種方式。一目瞭然。

Swift語言中的switch語句的妙用

相關文章

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.