Swift语言开发的各种坑

1、当写extension的时候  关联类型全局不能重复,否则会有影响

public final class YDSExtension<Base> {
    public let base: Base
    public init(_ base: Base) {
        self.base = base
    }
}

/**
 A type that has YDSExtension.
 */
public protocol YDSExtensionCompatible {
    associatedtype YDSExtensionCompatibleType  //不能重名
    var yds: YDSExtensionCompatibleType { get }
}

public extension YDSExtensionCompatible {
    public var yds: YDSExtension<Self> {
        return YDSExtension(self)
    }
}

extension UIView: YDSExtensionCompatible { }

 

发表评论

您的电子邮箱地址不会被公开。