Access control allows you to define what can access the properties and methods on your types. There are five levels of access control that can be applied to types, properties, and methods:
open. Used only for classes and mostly by framework or third-party library authors. Anything can access this class, property, or method. Additionally, classes marked as open can be subclassed, and methods marked as open can be overridden outside of the module.
public. Very similar to
publicclasses can only be subclassed and
publicmethods can only be overridden inside (not outside of) the module.
internal. The default level. Anything in the current module can access this type, property, or method. For an app, only files within the same project can access internal types, properties, and methods. If you write a third-party library, then only files within that third-party library can access them – apps that use your third-party library cannot.
fileprivate. Anything in the same source file can see this type, property, or method.
private. Anything within the enclosing scope can access this type, property, or method.