zoukankan      html  css  js  c++  java
  • 协议0

    //ProtocolClass.h

    #import <Foundation/Foundation.h>
    
    //声明一个协议:@protocol+协议名+满足的基协议
    @protocol MyselfDelegate <NSObject>
    
    @required//修饰的方法为必须实现的方法
    -(void)helloProtocolForR;
    
    @optional//修饰的方法为可选实现的方法
    -(void)helloProtocolForO;
    
    @end
    
    //<>表示该类遵守MyselfDelegate协议,则可以实现MyselfDelegate协议中的方法(.h无须再次声明)
    @interface ProtocolClass : NSObject<MyselfDelegate>
    
    @end

    //ProtocolClass.m

    #import "ProtocolClass.h"
    
    @implementation ProtocolClass
    
    //实现协议中的方法
    
    -(void)helloProtocolForR
    {
        NSLog(@"MyselfDelegate协议中必须实现的方法");
    }
    
    -(void)helloProtocolForO
    {
        NSLog(@"MyselfDelegate协议中可选实现的方法");
    }
    
    @end
    

    //AnotherProtocolClass.h另一个遵守

    1 #import <Foundation/Foundation.h>
    2 #import "ProtocolClass.h"
    3 
    4 @interface AnotherProtocolClass : NSObject<MyselfDelegate>
    5 
    6 @end

    //AnotherProtocolClass.m

    #import "AnotherProtocolClass.h"
    
    @implementation AnotherProtocolClass
    
    //实现协议中的方法
    
    -(void)helloProtocolForR
    {
        NSLog(@"MyselfDelegate协议中必须实现的方法");
    }
    
    -(void)helloProtocolForO
    {
        NSLog(@"MyselfDelegate协议中可选实现的方法");
    }
    
    @end
    

      

  • 相关阅读:
    Alpha 冲刺 (7/10)
    Alpha 冲刺 (6/10)
    同学录
    Alpha 冲刺 (5/10)
    Letcode刷题总结知识点
    python 基础语法
    Python 文件读写与编码解读
    py2exe界面和程序开发打包
    求职者五险一金解读
    互联网企业程序题总结
  • 原文地址:https://www.cnblogs.com/liuyingjie/p/4954005.html
Copyright © 2011-2022 走看看