Oc--protocol protocol

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.