Sorry for asking a stupid question. But I am confused about this:
var debugMessage: String {
return "Level 1"
}
Does that code mean the same as:
var debugMessage: String = "Level 1"
Or is it a closure?
The first:
var debugMessage: String {
return "Level 1"
}
is a short form of
var debugMessage: String {
get { return "Level 1" }
}
which is a computed property declaration with only a getter.
And the second is just a simple stored property declaration with an initialisation.
As you can see, one is a computed property and the other is a stored property. So their differences are mostly the same as the differences between computed properties and stored properties.
Here are a few of them.
var can be set
var debugMessage = { return "Lebel 1" }