cs193p – Assignment #2 Task #8

cs193p-assignment-2-task-8-winter-2017

Show the value of M (if set) in your UI somewhere.

Start by adding a new label to your storyboard. I put it into a new horizontal stack with the description display and increased the content hugging of the new label so that it only takes the necessary space:
cs193p-assignment-2-task-8-winter-2017-storyboard

Create an outlet for the new label in the view controller:

@IBOutlet weak var memoryDisplay: UILabel!

When ever the variables dictionary changes, change the memory display. First create an array from the dictionary using the keys and the values to create a nice display. Then join them to a string – note this way we do not care what the variables are named, or how many there are. As last step, use the existing beautify method to adjust the display for integers, or the correct decimal separator:

    private var variables = Dictionary<String,Double>() {
        didSet {
            memoryDisplay.text = variables.flatMap{$0+":\($1)"}.joined(separator: ", ").beautifyNumbers()
        }
    }

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

Facebooktwittergoogle_plusredditpinterestlinkedintumblrmailFacebooktwittergoogle_plusredditpinterestlinkedintumblrmail

Flattr this!

Leave a Reply

Your email address will not be published. Required fields are marked *