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{

        

    }

  • 相关阅读:
    /bin/bash^M:损坏的解释器: 没有那个文件或目录
    QT槽函数处理线程
    Strategy策略模式
    Proxy代理模式
    Ubuntu系统修改BIOS时间问题
    Ubuntu下安装Goldendict(翻译软件)
    自定义QMenu
    C connect实现Timeout效果(Windows)
    059 Python计算生态概览
    058 程序设计方法学小结
  • 原文地址:https://www.cnblogs.com/dhui69/p/11160074.html
Copyright © 2011-2022 走看看