Extension

  • Extensions add new functionality to an existing class, structure, enumeration, or protocol type.
  • You can extend types for which you do not have access to the original source code
  • Extensions are similar to categories in Objective-C. (Unlike Objective-C categories, Swift extensions do not have names.)

Extensions in Swift can:

  • Add computed instance properties and computed type properties
  • Can not add instance properties
  • Define instance methods and type methods
  • Provide new initializers
  • Define subscripts
  • Make an existing type conform to a protocol

results matching ""

    No results matching ""