我正在构建一款可以帮助人们找到附近酒吧的应用。但是,在构建我的应用程序时,需要一个预期的声明"出现错误:
import UIKit
import MapKit
class BarVC: UIViewController {
@IBOutlet weak var backBtn: UIButton!
@IBOutlet weak var barMapBtn: UIButton!
let regionRadius: Double = 1000
let request = MKLocalSearchRequest()
request.naturalLanguageQuery = "bars"
request.region = regionRadius
@IBAction func backBtnWasPressed(_ sender: Any) {
dismiss(animated: true)
}
}
这段代码不在应有的位置吗?我需要遵守什么吗?请帮助谢谢!
答案 0 :(得分:1)
在范围内调用您的代码
override func viewDidLoad() {
super.viewDidLoad()
let request = MKLocalSearchRequest()
request.naturalLanguageQuery = "bars"
request.region = regionRadius
}
或者你可以用作
let request = MKLocalSearchRequest()
override func viewDidLoad() {
super.viewDidLoad()
request.naturalLanguageQuery = "bars"
request.region = regionRadius
}