Apologies in advance if such a thing had already been proposed.
Sometimes, when constructing types, we separate some functionality and encapsulate it within different extensions (Delegate conformance, specific context responsibility etc.).
We often prefer also separating this functionality into separate files for better readability.
This works well until we need to access a property we want to "hide" from the outside world to express it shouldn't be accessed directly.
We can use private
or fileprivate
, but then we lose the ability to access it from a different file.
What I propose is a new keyword which makes properties and functions marked with it accessible only within this type.
For example:
MyType.swift
class MyType {
member var myString: String = ""
....
}
And then, in a separate file:
MyType+Delegate.swift
extension MyType: MyDelegate {
func foo() {
myString = "bar"
}
}
Trying to access myString
from outside the type causes a compilation error.
Of course, the keyword member
is just a suggestion, and can be changed.
Other options: context
, domain
, typemember
.
This is my first proposal, so I hope it's detailed sufficiently. I'd appreciate any input you may have.