Protocol(protocol)
(a) Introduction
2.Protocol: For a single use, declare a whole bunch of methods (cannot declare member variables), cannot write implementation.
3. Features: The agreement only stipulates what to do, regardless of how it is done
4. As long as a class complies with this agreement, it has all the method declarations in the agreement.
5. As long as the parent class adheres to a protocol, the subclass also follows.
6. the Protocol declaration method allows any class to be implemented, andProtocol is the protocol.
7.OC cannot inherit multiple classes (single inheritance) but can comply with multiple protocols. Inheritance (:), Compliance Agreement (< >)
8. Base protocol:<NSObject> is the base protocol and is the most fundamental and basic protocol, which declares many of the most basic methods.
9. The agreement is subject to the agreement, and one agreement complies with the other and can have a method statement in another agreement.
10. Multiple classes can implement the same protocol at the same time, a class can implement multiple protocols at the same time (syntax format: Comma separated by multiple protocols)11. The use of protocols can achieve polymorphism, method of dynamic binding, in the implementation of the process can find what you pass through, and then realize you pass over the.@required: The method that this method must implement (and the default) @ Optional: Represents an optional implementation method. Protocol declaration format: @protocol protocol name NSObject "Agreement of the parent class protocol implementation (other class implementation) format: @interface Student: nsobject<scsys>
(ii) basic use
Create a protocol
Implementation of the methods declared in the Protocol completion protocol The operation of the main function program
Oc--protocol protocol