Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

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

When I try this I get error:

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

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

When I try this I don't get error:

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

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

Why do I not add UIScrollViewDelegate to ViewController when I use extension?

If a class is type of UIViewController means it conforms to UIScrollViewDelegate ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

In the first code sample, you've already added conformance to UIScrollViewDelegate with the class declaration.

Now, when you try to conform to UIScrollViewDelegate again with the extension, swift screams at you.

For the second code sample the conformance is added in the extension. The class did not conform to UIScrollViewDelegate before the extension was added.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...