FWIW. Swift ( protected), Swift . , 3,5 , , Swift , Swift , , , .
- , 95% , . , , . , , , , , API , (, , ), API, , , .
, , , Objective C, protected, API ( ) "+ Subclassing", , .
Swift , :
open class SomeClass {
private var foo: String
private var bar: Data
public init(){
foo = "foo"
bar = Data()
}
private func doInternalThing() {
print(foo)
}
}
( , ), ( ) :
// Create a nested "Protected" type, which can accept an instance of SomeClass (or one of its subclasses) and expose the internal / protected members on it
public extension SomeClass {
public class Protected {
unowned private var someClass: SomeClass
public var foo: String {
get {
return someClass.foo
}
set {
someClass.foo = newValue
}
}
public init(_ someClass: SomeClass) {
self.someClass = someClass
}
public func doInternalThing() {
someClass.doInternalThing()
}
}
}
, :
class SomeSubclass: SomeClass {
private lazy var protected: SomeClass.Protected = { SomeClass.Protected(self) }()
func doSomething() {
protected.foo = "newFoo"
protected.doInternalThing()
}
}
. - , , , . , , SomeClass.Protected , , , , , , .
, , "" var, API. , - API , . SomeSubclass - API .
, , - - API - , Swift , Swift Swift, Twitter bugss.swift. .