gpt4 book ai didi

ios - 错误 : Redundant conformance of 'ViewController' to protocol with extension

转载 作者:行者123 更新时间:2023-11-28 12:11:16 25 4
gpt4 key购买 nike

当我尝试这个时,我得到了错误:

class ViewController: UIViewController, UIScrollViewDelegate {
......
}

extension ViewController: UIScrollViewDelegate { // Error: Redundant conformance of 'ViewController' to protocol 'UI
....
}

当我尝试这个时,我没有收到错误:

class ViewController: UIViewController {
......
}

extension ViewController: UIScrollViewDelegate { // No error
...
}

为什么我在使用extension的时候没有给ViewController添加UIScrollViewDelegate?

如果一个类是 UIViewController 类型意味着它符合 UIScrollViewDelegate ?

最佳答案

在第一个代码示例中,您已经使用类声明向 UIScrollViewDelegate 添加了一致性。

现在,当您尝试使用扩展再次符合 UIScrollViewDelegate 时,swift 会向您尖叫。

对于第二个代码示例,在扩展中添加了一致性。在添加扩展之前,该类不符合 UIScrollViewDelegate

关于ios - 错误 : Redundant conformance of 'ViewController' to protocol with extension,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48462074/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com