1. Extension: Swift uses an extension mechanism that can be used in the original class struct and enumeration, in the following format:
Extension type name {
New features
}
New features can be added in the original type (class, struct, enum) including: 1, instance computed properties and static computed properties 2, instance method and static method 3, constructor 4, subscript.
2, protocol: All methods are abstract, called Protocol (Protocol) similar to the C # interface. The protocol is highly abstract, and he has only abstract method names, parameter lists, and return values. Implementations become compliance protocols that implement both interfaces.
Declaration Agreement:
Protocol protocol Name {
Protocol contents such as Func GetInfo () do not need to implement curly braces []
}
Realize:
Type type name: Parent class (optional), Protocol 1, Protocol 2{
Concrete implementation of the Func GetInfo () {//Method implementation}
}
Note Static protocol, before adding class or Static, class representing classes (class Func GetName ()), static struct, enum enum enumimp:account{static func GetName () {}}
Extensions and Protocols