In Swift, we can set a stored property to use closure:
class Test {
var prop: String = {
return "test"
}()
}
vs
or make lazy stored property use closure:
class Test {
lazy var prop: String = {
return "test"
}()
}
In both cases, the code used to obtain the value for the property is only run once. It seems like they are equivalent.
When should I use lazy stored property versus computed property when using closure with it?