Why do I need to configure publishing before overriding viewDidload in open access controlController

Why do I need to configure the publication before overriding the viewDidload in the public domain access controlController

public class customViewController: UIViewController {
    override public func viewDidLoad() {
        super.viewDidLoad()
    }
}

If I delete the publication, Xcode will report an error!

+4
source share
3 answers

The error message is quite explicit:

An instance override method should be as accessible as declaring its override.

This means that the method should not have a lower level of access than the method that it overrides.

For example, this class:

public class Superclass {
    internal func doSomething() {
        ...
    }
}

You cannot override doSomethingwith a method that is less accessible than interal. eg.

public class Subclass : Superclass {
    // error
    private override func doSomething() {
    }
}

:

public class Subclass : Superclass {
    public override func doSomething() {
        // You can even call the internal method in the superclass
        super.doSomething()
    }
}

, , .

+6

Public , , . .

Internal access , - . .

Private . , .

File-private .

? :

class customViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
    }
}

+1

:

public class customViewController: UIViewController

customViewController public ()

:

override func viewDidLoad() {
    super.viewDidLoad()
}

, .

. , UIViewController UIViewController.

0
source

Source: https://habr.com/ru/post/1611736/


All Articles