Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Lana Wong
Lana Wong
3,968 Points

Stanford Tutorial

Hi. I started watching youtube videos on iOS created by Stanford. Can someone please explain this?

import UIKit

class ViewController: UIViewController {


    @IBOutlet weak var display: UILabel!

    var middleOfTyping = false

    @IBAction func touchDigit(_ sender: UIButton) {
        let digit = sender.currentTitle!

        if middleOfTyping{
            let currentNumbers = display!.text!
            display!.text = currentNumbers + digit

        }else{
            display!.text = digit
        }
        middleOfTyping = true
    }

}
Michael Hulet
Michael Hulet
47,913 Points

Be more specific. What is it exactly that you're having trouble with?

Lana Wong
Lana Wong
3,968 Points

Can you please explain what is happening in this code?

1 Answer

Lana Wong - you're referring to https://www.youtube.com/watch?v=HitSIzPM_6E (Paul Hegarty's famous CS193P course, nowadays only available on the iPad, https://itunes.apple.com/de/course/developing-ios-10-apps-with-swift/id1198467120) right?

It's all generally explained starting at around 26:18, the problem solved with this code is at 59:53 - it prevents the display label to use the initial 0 (zero) and append other numbers to it.

Could you please specify what exactly you find hard to understand, assuming that you already went through Treehouses iOS courses?

Furthermore:

middleOfTyping = true

is at least in the 1st course in the else block.

All the best for your programming journey!

Karsten