对象与协议的冗余一致性

问题描述 投票:0回答:1

尝试运行以下代码时出现此错误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)
    }
}
ios swift inheritance uiview protocols
1个回答
2
投票

[您只需要摆脱对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)
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.