๐ดProtocol Extensions
Last updated
Last updated
provide default implementations. (dynamic method dispatch) ๐ ๐ ๅ่
add new functionalities: (static method dispatch)
add methods
add (convenience) initializers (but not convenience override init)
add subscripts
add computed properties
make existing types conform to protocol.
ๅ๏ผprotocol extension ่ฃก้ขๅฏไปฅๅ nested types ๅ๏ผ
็ญ๏ผ็ฎๅ็ไพไธ่กโ๏ธ ( ๐ฃ ่จ่ซ)
Extensions can add new nested types to existing class, struct, and enum. (but not protocol extensions) Nested Types in Extensions
Declaring a method inside the protocol (definition) creates an extension point โ a method that we encourage conforming types to override.
If we put methods into the protocol extension but not the protocol definition, all conforming types still get the method, except now weโre making it harder for them to override. (๐ไพไบ)
define requirements for conforming types. (๐ไพไธ)