美文网首页
Swift中的delegate

Swift中的delegate

作者: fordring2008 | 来源:发表于2017-02-05 12:26 被阅读66次

// delegate

// 当一个协议 没有任何的父协议时,说明它是可以被 struct, enum 实现的,声明一个实现了这个代理类型的实例时,就不能使用 weak。如果要使用 weak, 就需指定实现让这个协议的是 class ,让它实现  : class

// 另一种做法是,在将协议声明为 oc 类型的,在前面加 @objc 关键字。因为 OC 协议都只有类能实现,用weak 也就合理了

// 我们通常的做法是,新建协议的时候,让他实现  NSObjectProtocol

protocol MyClassDelegate: NSObjectProtocol {

func method()

}

class MyClass {

weak var delegate: MyClassDelegate?

}

相关文章

  • Swift小知识

    1. 关于Swift中Protocol 1. 在 Swift 中,Delegate 就是基于 Protocol 实...

  • swift中的Delegate

    在iOS开发中,代理模式(protocol - delegate)是界面之间数据传递最为常见的一个设计模式 在Co...

  • Swift中的delegate

    // delegate // 当一个协议 没有任何的父协议时,说明它是可以被 struct, enum 实现的,声...

  • swift delegate 和 block 使用

    swift delegate 和 block 使用 delegate使用 //自定义cell 代码importUI...

  • UIApplication

    Swift 中没有了main函数,但是在app delegate中有@UIApplicationMain, 可以去...

  • delegate

    Swift的delegate 用weak修改的时候的注意事项Swift-代理

  • Swift 报 Type 'xx' does not confo

    Swift中设置完UITableView的delegate和数据源dataSource会报如下错误: 明明你该做的...

  • swift中的Delegate、Notification、Blo

    swift中的Delegate、Notification、block 的思路和实现过程和Object-C基本一致。...

  • swift delegate

  • Swift delegate

    ARC 中,对于一般的 delegate,在声明中将其指定为 weak,在这个 delegate 实际的对象被释放...

网友评论

      本文标题:Swift中的delegate

      本文链接:https://www.haomeiwen.com/subject/mgyjittx.html