typealias总结

2022-07-17 10:36:44

用来为已经存在的类型重新定义名字

阅读方便
typealias Location = CGPoint
typealias Distance = Double

自定义类型:OC和swift混编情况下,OC进行swift化。规避地项对搜索-查找-替换
// OC中项目里有个类
#import "OCClass.h"
// swift重构之后
impot SwfitClass
typealias OCClass = SwfitClass

定义闭包

typealias sendValueClosure = (sendString: String) -> Void//声明
var callBackString: sendValueClosure?//持有
self.callBackString!(sendString: self.nameString)//调用

protocol组合

多种protocol可以组合成一个,利用typealias重新命名
protocol changeName{
  func changeNameTo(name:String)
}
protocol changeSex{
  func changeSexTo(sex:SEX)
}
typealias changeProtocol = protocol<changeName,changeSex>

struct Persion:changeProtocol{
  func changeNameTo(name:String){
    ///
  }
  func changeSexTo(sex:SEX){
    ///
  }
}
  • 作者:Cocoanerd
  • 原文链接:https://blog.csdn.net/ZHFDBK/article/details/103569045
    更新时间:2022-07-17 10:36:44