zoukankan      html  css  js  c++  java
  • iOS-Swift协议中关联类型的使用

    Associated Type :关联类型

    有时候会遇到这样的需求,继承自某一协议的类中需要保证代理方法处理的参数类型保持一致,这就需要使用关联类型来做到这一点

    协议声明:

    protocol ATypeDelegate {

        associatedtype T

        func printContent( ct : T)

        func colum( ct : T)

    }

    协议使用:

    class ATypeClass: ATypeDelegate {

        typealias T = Int

        func printContent(ct: Int) {

            print("Int",#function)

        }

        

        func colum(ct: Int) {

            print("Int",#function)

        }

    }

    ATypeClass 继承自ATypeDelegate,必须在ATypeClass类中定义 T 的具体类型才能使用

  • 相关阅读:
    0427-2
    0427-1
    0426html常用标签属性
    HTML,标签学习
    oracle培训,HTML学习
    第三十七天
    第三十六天
    第三十五天
    第四十三天
    第四十二天
  • 原文地址:https://www.cnblogs.com/madarax/p/6873762.html
Copyright © 2011-2022 走看看