Ray Wenderlich Course Part 2 (up to lesson 21)

A brief entry here as I'm doing a bit of coding in between a hectic social time. The next time after this will be Monday, where I plan on doing a fair bit of Ray's course. Last time, some of the information wasn't all that clear, which he readily admitted at this stage. Still, there were lots of useful ideas. Here we go!

Objects, Data and Methods

Swift is object-oriented which basically means everything links to buttons, labels etc.





An object can have both data and functionality.







Example for methods - party!






So sending messages is a conceptual way of seeing how methods work. Calling a method, invoking a method - all the same thing.

Strings and Variables

 @IBAction func sliderMoved(_ slider: UISlider) {
        
        print("The value of slider is now: \(slider.value)")

    }

Variables have a certain life-time. As it's a variable, the value can change etc. etc.

currentValue = lroundf(slider.value)

This is because the currentValue (declared at top of code) is an Int! 

 let message = "The value of the slider is \(currentValue)"
        
        let alert = UIAlertController(title: "Hello guys!", message: message, preferredStyle: .alert)

So now the value of the slider is shown with the alert. Cool.

Challenge - your First Bug!

OK, so the bug is that the value is that the slider value will be stated at 0 when the app starts. It needs to be 50, so all I had to do was change the starting variable value to 50! Easy!

Connecting Outlets



OK these makes sense. Global is for the whole program. Instance is within the ViewController - if that is where the object is created. Local is only within that particular method.





*I do not like this way of connecting outlets. I want to do it my preferred way - the usual way!

Well, something's come up with this. Not sure why the value isn't updating as I'd like. I have to go so will frustratingly have to park this for now! Never mind, it's just that Ray's way of doing the outlets is so different with the code first. I will investigate properly on Monday and have a proper look then.

Comments

Popular posts from this blog

*Xcode Project Entry 2* F1 Quiz - part 1

Angela Yu Course Part 10 (up to lesson 112)

Angela Yu Xcode 12 Course - Part 7 (lectures 74 to 79)