Let's say I have a class
public class MyClass: NSObject, ABCDelegate {
func delegateMethod(a: a, b: b) {
...
}
}
This delegate method is being called by a singleton in MyClass
that handles some networking operations.
The thing is the compiler complains about Method 'delegateMethod(...)' must be declared public because it matches a requirement in public protocol 'ABCDelegate'
.
My question is:
private func
or simply func
If ABCDelegate is declared public and MyClass which adopts it is declared public, then the MyClass implementation of any members required by ABCDelegate must be declared public. It's as simple as that.
And if you think about it, it couldn't work any other way. Knowledge of MyClass is public. Knowledge of ABCDelegate is public. Knowledge of the fact that MyClass adopts ABCDelegate is public. Therefore knowledge of the fact MyClass implements the required members of ADCDelegate must be public - it follows as the night the day.
If you really wanted to, you could work around this by inserting a nonpublic object type into the chain of command. This compiles fine:
public protocol Proto {
func f()
}
public class A {
private var helper : B!
func g() {
helper.f()
}
}
private class B : Proto {
func f() {}
}
But it seems awfully silly. My recommendation is just do what the compiler tells you and move on.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With