cs193p – Project #1 Assignment #1 Internationalization

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

When running on a real device, which region is set to something having not a “.” as comma symbol, the app crashes. Strangely it does not crash on the simulator.

One way to cope with this behavior is to force the number formatter to use the US locale all the time:

           if let displayText = display.text {
                let numberFormatter = NSNumberFormatter()
                numberFormatter.locale = NSLocale(localeIdentifier: "en_US")
                if let displayNumber = numberFormatter.numberFromString(displayText) {
                    return displayNumber.doubleValue
                }
            }

Continue reading “cs193p – Project #1 Assignment #1 Internationalization”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs193p – Project #1 Assignment #1 Extra Task #5

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

Use Autolayout to make your calculator look good on all different kinds of iPhones in both Portrait and Landscape orientations (don’t worry about iPads for now). Just like we used ctrl-drag to the edges of our scene to position display, you can you ctrl-drag between your UILabels (and/or your C button) to fix their vertical/horizontal spacing relative to each other. Use the blue gridlines! It’s probably a good idea to reset all of your autolayout (via the button in lower right corner), then use ctrl-drag to add constraints to things that are not part of the grid of keypad and operation buttons, then use the buttons in the lower right to lay out those (after you’ve moved them in to place relative to your UILabel(s), etc., using dashed blue lines, of course!).

… which we did already for the previous task …

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs193p – Project #1 Assignment #1 Extra Task #4

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

Change the computed instance variable displayValue to be an Optional Double rather than a Double. Its value should be nil if the contents of display.text cannot be interpreted as a Double (you’ll need to use the documentation to understand the NSNumberFormatter code). Setting its value to nil should clear the display out.

Make the display value an optional. When getting the display value, check first if there is a text, then if the text is a number and return the double value. Otherwise return nil. When setting the display value, check if it is nil. If not set the text label to the value otherwise to zero.
Continue reading “cs193p – Project #1 Assignment #1 Extra Task #4”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs193p – Project #1 Assignment #1 Extra Task #3

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

Add a ᐩ/- operation which changes the sign of the number in the display. Be careful with this one. If the user is in the middle of entering a number, you probably want to change the sign of that number and allow typing to continue, not force an enter like other operations do. On the other hand, if the user is not in the middle of typing a number, then this operation would work just like any other unary operation (e.g. cos).

Change the label of one of the “invisible” buttons to the +/- sign:
Continue reading “cs193p – Project #1 Assignment #1 Extra Task #3”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs193p – Project #1 Assignment #1 Extra Task #2

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

When the user hits an operation button, put an = on the end of the UILabel you added in the Required Task above. Thus the user will be able to tell whether the number in the Calculator’s display is the result of a calculation or a number that the user has just entered. Don’t end up with multiple occurrences of = in your UILabel.

When the display value is set – which is basically every time an operation button is pressed – add the “=” to the history label but only if there is something to show:

    var displayValue: Double {
            ...
            let stack = brain.showStack()
            if !stack!.isEmpty {
                history.text = stack! + " ="
            }
        ...
    }

Continue reading “cs193p – Project #1 Assignment #1 Extra Task #2”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs193p – Project #1 Assignment #1 Extra Task #1

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

Implement a “backspace” button for the user to touch if they hit the wrong digit button. This is not intended to be “undo,” so if the user hits the wrong operation button, he or she is out of luck! It is up to you to decide how to handle the case where the user backspaces away the entire number they are in the middle of typing, but having the display go completely blank is probably not very user-friendly.

Change the label of one of the “invisible” buttons to “BS”:
Continue reading “cs193p – Project #1 Assignment #1 Extra Task #1”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail