OC與Swift的區別四

來源:互聯網
上載者:User

標籤:

12.條件陳述式的區別,此處唯寫區別,沒有指出區別的其他方面oc與swift基本一致

 

12.1

oc中for if switch語句體如果只有一行代碼,則{}可以省略

swift中for if switch語句體必須使用{} ,否則有語法錯誤

 

12.2for-in文法的區別:

   //從1迴圈到3,包括3,即迴圈3次

   for i in 1..3{

  }

   //如果不需要用到迴圈條件範圍中的值,則使用_忽略該迴圈條件值,使其在迴圈體內不會建立局部變數

  for _ in 1..3{

  }

   //迴圈條件值是常量,在迴圈體內不能改變

  for i in 1...3{

     i = 10   //此代碼報錯

  }

OC與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.