Given a class property, you can specify a different access level by prefixing the property declaration with the access modifier followed by get or set between parenthesis. For example, a class property with a public getter and a private setter will be declared as:
private(set) public var readonlyProperty: Int
Suggested reading: Getters and Setters
Martin’s considerations about accessibility level are still valid – i.e. there’s no protected modifier, internal restricts access to the module only, private to the current file only, and public with no restrictions.
Swift 3 notes
2 new access modifiers, fileprivate and open have been added to the language, while private and public have been slightly modified:
-
openapplies to class and class members only: it’s used to allow a class to be subclassed or a member to be overridden outside of the module where they are defined.publicinstead makes the class or the member publicly accessible, but not inheritable or overridable -
privatenow makes a member visible and accessible from the enclosing declaration only, whereasfileprivateto the entire file where it is contained
More details here.