Declaration error

Hey so I even restarted my Mac and it still shows the same issue. Literally the only thing stopping me from moving to better things lol.

Hey David! Can you paste your whole code here please :slight_smile:

Thanks! XD

Where are leftNumber and rightNumber defined?

@David_Clark FYI, it’s far easier to just paste in the code rather than a bunch of screenshots. It also makes it easy for other posters to copy your code and try it out in working towards a solution; saves having to retype everything from scratch.

And if you post your code fenced with backticks (``` before and after your code block), it will turn out like this:

func doSomething() {
    //blah blah blah

with nifty formatting!

Hahaha, ur right. Laziness is its own dem0n lol

On line 55 there’s an “s” just sitting before a curly brace. Is that deleted?

Please paste your whole code. Like @roosterboy said. It’s hard to read just single screenshots

1 Like

let leftNumber = Int.random(in: 2…14)
let rightNumber = Int.random(in: 2…14)
So this sequence of code sets the leftNumber as a constant and verifies it.

leftImageView.image = UIImage(named: “card(leftNumber)”)

    rightimageView.image = UIImage(named: "card\(rightNumber)")

This marks it so it is now tied to leftImageView

if leftNumber > rightNumber {
Here’s the issue. There’s a declaration error In the if statement

Hi David,

The curly bracket right above your left number has got the rest fo the method out of scope. This is why it can’t see the declaration right above it. Delete it there and then follow the braces, to put it on the end of the method.


1 Like

Thanks Foundation. It got rid of the declaration error but now its saying it needs a closing for my beginning class at the top of the swift list. It needs a match. class ViewController: UIViewController {

@IBOutlet weak var leftImageView: UIImageView!

@IBOutlet weak var rightimageView: UIImageView!

@IBOutlet weak var leftScoreLabel: UILabel!

@IBOutlet weak var rightScoreLabel: UILabel!

Hi David,

Yea, these nested If statements get me all the time. Start at the top and double click each curly bracket, Xcode will select everything below it wants to connect in the scope.

I expect you will just need to add one more bracket at the end of the dealTapped method.


Ur advice helped but now its just saying I’ve added too many curly brackets. Should I restart my Mac?

I don’t see why you would need to restart your Mac.

Just go through each function and where a curly brace is used make sure you have a corresponding curly brace at the end, in the RIGHT location.

Yep, Mikaela beat me to it. No need to restart. I start at the top and double click that to se how far it goes down, then wok up for the bottom of that selection, double clicking the top of each pair of braces.

You are on the right track.

Haha guys I’m saying I did that and still no change occurred. The curly bracket showed me where to add the curly bracket and it once I added one it said it was extraneous (excess).

I fixed it. Thanks for reaching out.

Please share your solution, it may help others encountering the same problem