I read the document about Swift 5.1 from swift.org and have some questions about access level in enumeration.
https://docs.swift.org/swift-book/LanguageGuide/AccessControl.html#ID14
In the document, it says:
The individual cases of an enumeration automatically receive the same access level as the enumeration they belong to.
private enum SomePrivateEnum {
case one
case two
case three
}
private class SomePrivateClass {
private var somePrivateProperty = 0
}
// work
print(SomePrivateEnum.one)
// error: 'somePrivateProperty' is inaccessible due to 'private' protection level
print(SomePrivateClass().somePrivateProperty)
According to the document, if I have a private
enum, then all cases should receive private
access level. The question is, why can I access the private case outside the enum declaration ? This behavior is different from Class
.