Reputation: 20815
I was recently browsing through the DemoBots example from Apple and I came across:
/// The scene that is currently being presented.
private (set) var currentSceneMetadata: SceneMetadata?
What exactly does (set)
do and what other options (if any) are available here?
Upvotes: 4
Views: 735
Reputation: 3077
It means only setter is private. So currentSceneMetadata access for get is the default--which is internal-- but that of set is private. So it can only be changed from within the same source file.
Link to confirm: https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/AccessControl.html
EDIT: You could even do something like this:
public private (set) var name: String
which means name's access level for setter is private and for getter is public.
Upvotes: 9