These are chat archives for devslopes/swiftios9

24th
Oct 2015
mas2015
@mas2015
Oct 24 2015 01:50
image.PNG
Capture2.PNG

Hello, I am getting this error every time I run the simulator. This is for lecture 10 exercise. Thanks.
import UIKit

class ViewController: UIViewController {

@IBOutlet weak var bombBlue: UIImageView!

@IBOutlet weak var bombRed: UIImageView!


override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}


@IBAction func disappearBlueBomb(sender: AnyObject) {
    bombBlue.hidden = true

}


@IBAction func disappearRedBomb(sender: AnyObject) {
    bombRed.hidden = true

}

}

Mark Price
@spentak
Oct 24 2015 01:54
@mas2015 a very common error. it happens when you forgot to connect your view in your storyboard to your IBOutlet in your code :)
mas2015
@mas2015
Oct 24 2015 02:01
I looked at the source code solution and it looks the same to me.
Mark Price
@spentak
Oct 24 2015 02:01
its not your code
you need to drag the connection from the view to the outlet
mas2015
@mas2015
Oct 24 2015 02:24
Do you mean ctrl click and dragging the connection from the image on the view controller storyboard into the view controller.swift section?
Sketchy Swift
@HardcoreIOS
Oct 24 2015 02:29
This message was deleted
Screen Shot 2015-10-23 at 10.29.08 PM.png
Click on the storyboard yellow icon. Right-click
Then delete the ones that have yellow triangles on it
@mas2015 ^^^
mas2015
@mas2015
Oct 24 2015 02:46
The app is working now. Thanks.
Sketchy Swift
@HardcoreIOS
Oct 24 2015 03:00
Welcome
Mark Price
@spentak
Oct 24 2015 03:57
@mas2015 great!
andyaf
@andyaf
Oct 24 2015 20:51
Having some issues with the first exercise (blue button and red button). I receive error " * Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<Exercise_1_Try_2.ViewController 0x7fd8a8421150> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key hideBlue.' " (hide blue is the IBAction name). Any ideas how this can be solved?
Mark Price
@spentak
Oct 24 2015 20:52
@andyaf welcome . it means your storyboard view is not connected to your IBOutlet in code
Dulio Denis
@duliodenis
Oct 24 2015 21:50
Hello, World!
Jesus Lopez De Nava
@lodena
Oct 24 2015 23:54
Hello everyone!
In Lecture 41, I get the general gist of the lesson (I'm 100% new to Object Oriented Programming and classes). Having said that, in the example given by @spentak I understand the get portion. But the set part is the one I'm having problem understanding fully. As far as I can tell, when let's say we code bmw.odometer = 700 the private var _odometer is the one that gets updated not the public var odometer. But the program still somehow updates it because when I code print(bmw.odometer) it returns 700. Could someone helps me understand how this works?
Thanks!
class Vehicle {

    private var engine = "4 cylinder"
    private var color = "Silver"
    private var _odometer = 500

    //GETTER - SETTER (Accessors & Mutators)
    var odometer: Int {
        get {
            return _odometer
        }

        set {
            if newValue > _odometer {
                _odometer = newValue
            }
        }
    }

    init(engine: String, color: String) {
        self.engine = engine
        self.color = color
    }

    init() {

    }

    func enterMiles(miles: Int) {
        odometer += miles
    }

}
Murat Cakmak
@muratcakmak
Oct 24 2015 23:57
Wherever Mark uses “_” as a suffix of a variable, the variable is private. It is just his choice. Maybe, you can add “.private” prefix after each private variable.
Jesus Lopez De Nava
@lodena
Oct 24 2015 23:59
Yes, I get that. What I don't get is how the public variable was set to 700, if the code only says _odometer = newValue, not odometer = newValue.
Murat Cakmak
@muratcakmak
Oct 24 2015 23:59
In this sense, one cannot mess with your private variable out of class scope. I mean, one can only change the private variable inside the class. It is really good for debugging and pushing other user of the class to obey your rules.