Expected Declaration Error for Making High Score

Expected Declaration Error using Swift

The problem is that you need to put your code inside a method. All you need is to move it to viewDidLoad() or any other method.

swift compiler shows Expected declaration error?

I think you have the code in the wrong place in the class same like this question.

so move it to any function or in viewDidLoad method.

Hope it will help.

Swift Compiler Shows Expected Declaration Error

call your code in inside the scope

override func viewDidLoad() {
super.viewDidLoad()

let request = MKLocalSearchRequest()
request.naturalLanguageQuery = "bars"
request.region = regionRadius

}

or you can use as

 let request = MKLocalSearchRequest()
override func viewDidLoad() {
super.viewDidLoad()
request.naturalLanguageQuery = "bars"
request.region = regionRadius

}

swift expected declaration error

You need to pass your name variable to some kind of method in order for it to work such as viewDidLoad.

@IBOutlet weak var name: UITextField!

override func viewDidLoad() {

name

}

Xcode shows a Expected declaration error with any variable put in

You need to move that assignment either to declaration or into valid scope:

1:

var cpuSting = "Intel i5"

2:

override func viewDidLoad() {
super.viewDidLoad()
cpuSting = "Intel i5"
}

What you do in your code is essentially attempting to make an assignment in an improper place. If you declare a variable, then just declare it with required initial value. If you want to re-assign a value, then just do that in the right place, such as in instance method scope like viewDidLoad.



Related Topics



Leave a reply



Submit