报错Extensions must not contain stored properties
这个时候我们应该使用关联属性来实现想要的功能
public extension UIView {
private struct AssociatedKey {
static var clipType: CornerClipType = .None}var clipType: CornerClipType {
get {
return objc_getAssociatedObject(self, &AssociatedKey.clipType) as? CornerClipType ?? CornerClipType.None}set {
objc_setAssociatedObject(self, &AssociatedKey.clipType, newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)}}
}
搞定