So, I am writing a Swift structure where I want to publish some objects publicly only through protocol
.
eg:
public protocol Thing : class {
var x : Int { get }
}
I want to hide the details of my implementation, so I create a class internal
:
internal class ThingImpl : Thing {
public private(set) var x : Int = 0
}
And release a new one Things
using the factory method:
public func newThing() -> Thing {
return ThingImpl()
}
I can’t understand why the compiler warns me about creating var x
public
inside ThingImpl
and calls me to declare it internal.
Everything works fine, despite the warning, and if I listen to the warning and go on internal private(set) var x : Int = 0
, the warning will disappear and everything will work fine.
, var , , .
- ? .