The iOS protocol

Recommended for you: Get network issues from WhatsUp Gold. Not end users.

In IOS protocol: you take a look feel very advanced   in IOS protocol is C, java interface is a changed form,

Feel IOS the agreement not in C interface   others interface is fixed content program your   while IOS protocol and little conflict.

The following write a protocol   please see the following program

Mr. a propcle protocol   inheritance in this agreement statement Pro classes and through the main function call

#import <Foundation/Foundation.h>


@protocol Prorocol <NSObject>



//It must be defined function   that is to say the function must implement the pro class if the step to realize the compiler error reporting  



@optional  //He defined below some   even if this function is not implemented in the pro class is not error






@interface Pro : NSObject<Prorocol>



@implementation Pro




    NSLog(@"I is a must");




    NSLog(@"I am available");









int main(int argc, const char * argv[])



    @autoreleasepool {

// insert code here...

Pro *p=[[Pro alloc] init];

[p print2];

[p print];

NSLog(@"Hello, World!");


    return 0;


 The operation results:

If we take the print function above class deletion of   the compiler will give us

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Joe at December 03, 2013 - 7:21 PM