Swift 擴充(Extension)總結

來源:互聯網
上載者:User

標籤:計算   col   strong   cat   覆蓋   objective   沒有   protocol   cti   

擴充是給已經存在的類(class),結構體(structure),枚舉類型(enumeration)和協議(protocol)增加新的功能。類似Objective-C中的Category,不同的是,Extension沒有名字。擴充可以做以下事情:

  • 增加計算執行個體屬性和計算類型屬性
  • 定義執行個體方法和類型方法
  • 提供新的初始化器
  • 定義下標
  • 定義和使用新的內建類型
  • 讓一個存在的類型服從一個協議

註:擴充可以增加新的功能,但是不能覆蓋已有的功能


和oc相比是閹割版本。

Swift 擴充(Extension)總結

相關文章

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.