zoukankan      html  css  js  c++  java
  • Swift 协议protocol

    // associatedtype 关键字 用来声明一个类型的占位符作为协议定义的一部分

    protocol LXFViewModelType {

        associatedtype Input

        associatedtype Output

        

        func transform(input: Input) -> Output

    }

    /*

     定义协议时候,协议后面最好跟上class

     delegate的属性最好用weak,用于防止循环引用

     */

    protocol BuyTicketDelegate : class{

        func buyTicket()

    }

     

    class Person22{

        weak var delegate:BuyTicketDelegate?

        

        func gotoBeiJing() {

            delegate?.buyTicket()

        }

    }

     

     

    /*

     定义可选类型的协议

     optional属于OC特性,如果协议中油可选的方法,那么必须在protocol前面加上@objc,也需要在optional前面加上@objc

     */

    @objc protocol TestProtocol{

        @objc optional func test()

    }

     

    class Dog:TestProtocol{

        

    }

  • 相关阅读:
    CMLLVDS
    js获取url中的参数(解决中文乱码)
    解决跳转出现 No input file specified.
    ThinkPHP关联模型详解
    Thinkphp表单自动验证
    手机号登录注册
    JS实现每隔一段时间数量增加或减少
    文章或者观点说说等点赞功能实现(thinkphp)
    thinkphp整合Ueditor编辑器
    点击切换状态 类似开关按钮
  • 原文地址:https://www.cnblogs.com/dhui69/p/11160074.html
Copyright © 2011-2022 走看看