Protocol for Ios development: protocol for ios development

Source: Internet
Author: User

Protocol for Ios development: protocol for ios development

Protocol is a difficult and important point in ios development. To use it well or understand it well, it may take time to accumulate. Today, let's take a simple look at how to use protocol through an example.

The example we use today is to simulate computer insertion of a usb device to analyze the use of protocol.

First, let's take a look at the protocol between our usb device and the computer's pci interface. Otherwise, our usb device cannot be used on the computer!

Assume that the usb protocol we simulate is such a usb protocol.

This Protocol specifies that power-on is a method that must be implemented. @ required can be used to modify the declared method. In this way, we must implement the method when the class complies, the method declared by @ optional is implemented when the class complies with this Protocol!

With this protocol, we can simulate the production of usb devices and create the following two classes: A small fan with a USB interface and a usb flash drive.

In the fan class, the fan complies with the Protocol but only implements the power-on function that must be implemented!

All methods of the Disk class are implemented.

Next, we start to create our computer

We can add a protocol variable for implementing the usb protocol to the computer class to simulate setting a usb interface on the computer and add a function to be implemented after the usb device is inserted!

Simulate the usb device insertion status in the main function

Use the set Method to insert data to the usb interface. We will find that the calling method is implemented in different files when different devices are in and out and running!

 

Author: Jerry Education
Source: http://www.cnblogs.com/jerehedu/
Copyright Disclaimer: The copyright of this article is shared by Yantai jereh Education Technology Co., Ltd. and the blog Park. You are welcome to repost it. However, you must keep this statement without the consent of the author and provide the original article connection clearly on the article page, otherwise, you are entitled to pursue legal liability.
Technical Consultation:

Related Article

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.