
上QQ阅读APP看书,第一时间看更新
Getting ready
In Swift, syntax is pretty easy, and that's why it is awesome. To extend any type, just type the following:
extension TypeToBeExtended{ }
Inside the curly braces, you can add your extensions to the type to be extended. In extension, you can do the following:
- Adding instance- or class-computed properties
- Adding instance or class methods
- Adding new initializers
- Defining subscripts
- Adding nested types
- Conforming to protocols
Once you create an extension to any type, the new functionality will be available for all instances in the whole project.