cs193p – Assignment #2 Task #5

We made the result, description and resultIsPending vars non-private API in Assignment 1. That means we signed up to continue to support them even though we are now adding a new feature (variables) in this assignment which sort of makes them irrelevant. Really what we want to do is deprecate these (you’ll see all sorts of deprecated iOS API in Xcode), but for now we will keep the old result, description and resultIsPending vars around and just implement each of them by calling evaluate with the argument nil (i.e. they will give their answer assuming the value of any variables is zero). However, do not use any of these vars anywhere in your code in this assignment. Use evaluate instead.

We use already the evaluate method for those three properties. Just place something like the following above each of them:

@available(*, deprecated, message: "no longer needed ...")

… and don’t use them any more in the view controller:

    @IBAction func performOperation(_ sender: UIButton) {
        ...
        let evaluated = brain.evaluate()        
        if let result = evaluated.result {
            displayValue = result
        }        
        if "" != evaluated.description {
            descriptionDisplay.text = evaluated.description.beautifyNumbers() + (evaluated.isPending ? "…" : "=")
        } else {
            descriptionDisplay.text = " "
        }
    }

The complete code for the assignment #2 task #5 is available on GitHub.

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

Leave a Reply

Your email address will not be published.