appbrewery / Magic-8-Ball-iOS13

Learn to Code While Building Apps - The Complete iOS Development Bootcamp
https://www.appbrewery.co
96 stars 543 forks source link

exception thrown #1

Open jessephillips opened 4 years ago

jessephillips commented 4 years ago

Forgive me if this is silly for me to suggest. But I got an error when running this app with only some small code changes I made. I'm wondering if something is funky. As a novice, I wasn't able to figure out the problem.

Here's my error: Thread 1: Exception: "[<Magic_8_Ball.ViewController 0x7fbd385071e0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key askButtonPressed."

my code: viewcontroller.swift `import UIKit

class ViewController: UIViewController {

@IBOutlet weak var imageView: UIImageView!

@IBAction func askButtonPressed(_ sender: UIButton) {
    let ballsArray = [#imageLiteral(resourceName: "ball3"),#imageLiteral(resourceName: "ball3"),#imageLiteral(resourceName: "ball5"),#imageLiteral(resourceName: "ball2"),#imageLiteral(resourceName: "ball1")]
    imageView.image = ballsArray.randomElement()
}

}`

Ramstan1010 commented 4 years ago

Hey @jessephillips, I also ran into this problem and it ended up being due to calling it something different originally and even though I did a refactor to rename it, it still didn't resolve. In your case it looks like you called it what you should so I'm not sure why, but I ended up searching for my incorrect button name (CMD+F) with the Main.Storyboard open and found it still existing incorrectly in the Connections Inspector (top right of screenshot). I deleted it from there and then remade the IBAction and it resolved my issue. Hope this helps!

image