Read-only property

I know I can use the "let" keyword to define a read-only property on a class. But I want one that can be changed by the class itself. I came up with this:


private gip: Bool = false
var gameInProgress: Bool {
     return gip
}


Now only the class functions can change the property. But is there a more elegant way to do this?

Accepted Reply

Yes.

private(set) var gameIsInProgress = false

Notice how I added "is"; that seems to be convention and would read better if you could abstract the game into at least a tuple, if not struct/class.

Replies

Yes.

private(set) var gameIsInProgress = false

Notice how I added "is"; that seems to be convention and would read better if you could abstract the game into at least a tuple, if not struct/class.