Beginner error

Hello I am beginner learning iOS development from YouTube. I am writing the same exact code as that in video but I am getting error saying "Expressions are not allowed at the top level"

The code is:

import SwiftUI

var highscore = 0 highscore = 99

the error is shoeing for last line of code. Would be grateful if anyone could help!

Replies

You have two statements on one line without a semicolon separating them. You can't do that in Swift.

var highscore = 0 highscore = 99

Place the statements on separate lines.

var highscore = 0
highscore = 99

You could also simplify things by setting the value to 99 at the start.

var highscore = 99

I don't know if that's enough to fix the build error. You didn't show much code.

I recommend Hacking with Swift's 100 Days of SwiftUI free course to learn iOS development. They also have a forum where you can ask questions if you run into problems when going through the course. Their forum is more beginner friendly than this forum.

https://www.hackingwithswift.com/100/swiftui