Temperature.celsiusValue should be a computed property
Opened this issue · 1 comments
stephencelis commented
The problem with a lazy var
is you can overwrite it:
Tropos/Tropos/Models/Temperature.swift
Lines 19 to 21 in 877990c
let temp = Temperature(fahrenheitValue: 20)
temp.celsiusValue = 20
The math isn't particularly expensive, so using a computed variable is probably good enough. If we really want to lazily load the celsius value, we can do so with a private lazy var
, which the computed variable calls/returns.
jakecraige commented
Interesting find. Computed variable makes sense to me.