The 5 access control keywords.
|
|
Protected does not exist because:
- It is ambiguous as to whether an extension should be able to access it
- Subclass methods could expose it anyway
All vars/classes/types/entities have a access level of internal by default.
Modifiers:
- If you give something the @testable attribute, it will be accessible by the testing classes, but maintain status as internal/private otherwise.
- You can define access control to an entire class/struct. This will also carry through for all it’s members (properties, methods, initializers, and subscripts)
- If you create a tuple out of two differently access controlled types, it will assume the most restrictive one.
- A function will be as restrictive as it’s parameters or return types are, unless you specify.
- Enum cases cannot have different levels of access, as well as their raw and associated values
- Type aliases can only have the same access level, or a more restrictive one.* this is an oversimplification
Originally published 04/11/2021 @ https://pittcsc.org/ Discord
Published here on 09/08/2022. Blog published date reflects the original date of publication.