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: