I saw this line of code in one of the classes from a project at work.
static private(set) var shared = UserPreferences()
I dont understand the use of (set) keyword in the above declaration. Tried normal googling but was unable to find anything useful. Can someone kindly explain its use? Thanks!
>Solution :
This is not a set keyword but a private(set) keyword.
This makes the var accessible as internal but constricts the write (set) access to private.
So this value can only be set from inside the type it is defined in. But can be read from anywhere in the module that the type is defined in.
You can read more about this here… https://docs.swift.org/swift-book/LanguageGuide/AccessControl.html#ID17