• 最精简 代理代码


    @protocol XieYi <NSObject>

    //1, 定义

    - (void)star;

    @end

    @interface Shixian : NSObject <XieYi>

    @end

    @implementation Shixian

    //4, 实现

    - (void)star

    {    

        NSLog(@" 这是 协议方法的 实现");

    }

    @end

    @interface ShiYong : NSObject

    //2, 设置属性

    @property (nonatomic,assign) id <XieYi> delegate;

    - (void)crying;

    @end

    @implementation ShiYong

    //3 发起使用

    - (void)crying

    {   //3, 使用

        [self.delegate star];

    }

    - (void)dealloc

    {

        self.delegate = nil;

        [super dealloc];

    }

    @end

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

        @autoreleasepool {

            Shixian *shixian = [Shixian new];

            ShiYong *shiyong = [ShiYong new];

            //5,设置代理

            shiyong.delegate = shixian;

            //6,

            [shiyong crying];

        }

        return 0;

    }

  • 相关阅读:
    7
    6
    5
    3
    4
    2
    1
    寒假工作经历
    软件工程第三周的总结
    软件工程第三周的学习报告 html<input> final finally finalize 的比较 BigInteger
  • 原文地址:https://www.cnblogs.com/iOS-mt/p/4248652.html
Copyright © 2020-2023  润新知