cs193p – Project #2 Assignment #2 Task #11

von uploader (Eigenes Werk) [Public domain], via Wikimedia Commons

Please note, this blog entry is from a previous course. You might want to check out the current one.

When you touch the C button, the M variable should be removed from the variableValues Dictionary in the CalculatorBrain (not set to zero or any other value). This will allow you to test the case of an “unset” variable (because it will make evaluate() return nil and thus your Calculator’s display will be empty if M is ever used without a →M).

… well … we (I) just reset the whole calculator brain by throwing away the old brain and creating a new one. Thus, also the variable values are reset by default. Maybe that was not the intended way to do …

If you have another better solution, please post them in the comments section!


6 thoughts on “cs193p – Project #2 Assignment #2 Task #11”

  1. My solution is slightly different and doesn’t require to nullify the brain as the brain may have trained certain Ops using knownOps.

    In Brain I have a reset method:
    func reset() {
    opStack = []
    vaiableVaules[] = [:]

    In Controller ..I set the display and historyLabel to empty space and call the above reset function:
    @IBAction func clear() {
    displayValue = nil
    history.text = ” ”

Leave a Reply

Your email address will not be published.