## cs193p – Assignment #1 Task #5

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:
[swift]
var description: String {
get {
if pending == nil {
return descriptionAccumulator
} else {
return …
}
}
}
private var descriptionAccumulator = "0"
[/swift]

## cs193p – Assignment #1 Task #3 & #4

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

Add some more operations buttons to your calculator such that it has at least a dozen operations total (it can have even more if you like). You can choose whatever operations appeal to you. The buttons must arrange themselves nicely in portrait and landscape modes on all iPhones.

Add the new operations to the calculator model:
[swift]
private var operations: Dictionary<String,Operation> = [

"x²" : Operation.UnaryOperation({ pow(\$0, 2) }),
"x³" : Operation.UnaryOperation({ pow(\$0, 3) }),
"x⁻¹" : Operation.UnaryOperation({ 1 / \$0 }),
"sin" : Operation.UnaryOperation(sin),
"cos" : Operation.UnaryOperation(cos),
"tan" : Operation.UnaryOperation(tan),
"sinh" : Operation.UnaryOperation(sinh),
"cosh" : Operation.UnaryOperation(cosh),
"tanh" : Operation.UnaryOperation(tanh),
"ln" : Operation.UnaryOperation(log),
"log" : Operation.UnaryOperation(log10),
"eˣ" : Operation.UnaryOperation(exp),
"10ˣ" : Operation.UnaryOperation({ pow(10, \$0) }),
"x!" : Operation.UnaryOperation(factorial),
"xʸ" : Operation.BinaryOperation(pow),
]
[/swift]

## cs193p – Assignment #1 Task #1 & #2

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

Get the Calculator working as demonstrated in lectures 1 and 2.

… done during the lectures …

Your calculator already works with floating point numbers (e.g. if you touch 3 ÷ 4 =, it will properly show 0.75), however, there is no way for the user to enter a floating point number directly. Fix this by allowing legal floating point numbers to be entered (e.g. “192.168.0.1” is not a legal floating point number!). You will have to add a new “.” button to your calculator. Don’t worry too much about precision or significant digits in this assignment.

The storyboard contains already the “.” button from the lecture.

Similar to userIsInTheMiddleOfTyping add a new boolean property to indicate that the user is in the middle of entering a floating point number:
[swift]
private var userIsInTheMiddleOfFloatingPointNummer = false
[/swift]

## cs193p – Lecture #2 – Applying MVC

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

The second lecture continues with the demo showing features of Swift and stacks in the interface builder.

The lecture as well as its slides are available via iTunes named “Applying MVC”. The code for the demo is available on GitHub.

## cs193p – Lecture #1 – Course Overview and Introduction to iOS, Xcode, and Swift

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

The cs193p course has started a new edition #Spring2016 featuring iOS 9.

Like every year lecture #1 is an general introduction of the course with an overview about iOS, MVC and a life demonstration of creating a calculator app.

The lecture as well as its slides are available via iTunes named “Course Overview and Introduction to iOS, Xcode, and Swift”. The code for the demo is available on GitHub.