Swift Programming Language has this to say about access control for extension:
You can extend a class, structure, or enumeration in any access context in which the class, structure, or enumeration is available. Any type members added in an extension have the same default access level as type members declared in the original type being extended. If you extend a public or internal type, any new type members you add will have a default access level of internal. If you extend a private type, any new type members you add will have a default access level of private.
Alternatively, you can mark an extension with an explicit access level modifier (for example, private extension) to set a new default access level for all members defined within the extension. This new default can still be overridden within the extension for individual type members.
I don't fully understand the above statement. Is it saying the following:
public struct Test { }
extension Test {
// 1. This will be default to internal because Test is public?
var prop: String { return "" }
}
public extension Test {
// 2. This will have access level of public because extension is marked public?
var prop2: String { return "" }
extension Test {
// 3. Is this the same as the above public extension example?
public var prop2: String { return "" }
}
prop2is conflicting with Apple Document:If you extend a public or internal type, any new type members you add will have a default access level of internal.Or am I understanding it wrong? - nahung89