Extension Class Can do

  • add init function

```swift

enum MyBool: Int {

case myTrue, myFalse

}

extension MyBool: ExpressibleByBooleanLiteral {

init(booleanLiteral value: Bool) {

self = value ? .myTrue : .myFalse
}

}
```

  • add instance/type methods

  • add calculate properties

  • add runtime properties

  • add conforming protocol

Extension Class cannot do

  • cannot add "required" init
    不能定义 required 的初始化⽅法的。
    我们⽆法为现有的⾮ final 的 class 添加required init

  • cannot add stored properties

results matching ""

    No results matching ""