对象对协议的冗余一致性

Redundant conformance of Object to Protocol

我在尝试 运行 下面的代码时出现此错误 Redundant conformance of 'AnyView' to protocol 'Pressable'。任何人都可以显示错误或任何其他方式来使用协议执行相同的登录。

class AnyView: UIView, Pressable {

}

// MARK: - Pressable

protocol Pressable: UIView {

}

extension UIView: Pressable {
    // touchesBegan
    override open func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        super.touchesBegan(touches, with: event)
        scaleAnimation(value: 0.8)
    }
}

您只需摆脱 AnyViewPressable 的一致性,因为它的超类 UIView 已经符合 Pressable.

class AnyView: UIView {

}

// MARK: - Pressable

protocol Pressable: UIView {

}

extension UIView: Pressable {
    // touchesBegan
    override open func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        super.touchesBegan(touches, with: event)
        scaleAnimation(value: 0.8)
    }
}