Please note, this blog entry is from a previous course. You might want to check out the current one.
Add a String property to your CalculatorBrain called description which returns a description of the sequence of operands and operations that led to the value returned by result. “=“ should never appear in this description, nor should “…”.
Let’s add a public string property called description, and compute it – like the result property – from another new private string property – the description accumulator. When no operation is pending, we can just return the accumulator otherwise we will have to do a little bit more:
var description: String { get { if pending == nil { return descriptionAccumulator } else { return ... } } } private var descriptionAccumulator = "0"
Continue reading “cs193p – Assignment #1 Task #5”