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
Setting Constraints Programmatically
Get Date and Time from Apple Server
iOS 8 Keyboard Hides My Textview
How to Get Managedobjectcontext for Viewcontroller Other Than Getting It from Appdelegate
How to Do Authentication in Uiwebview Properly
Uiviewcontroller In-Call Status Bar Issue
How to Express Strings in Swift Using Unicode Hexadecimal Values (Utf-16)
Avcapturesession Audio Doesn't Work for Long Videos
Massive Memory Leak in iOS Uiwebview
Alert View Is Showing White Rectangle in iOS7
Contentview Not Indenting in iOS 6 Uitableviewcell Prototype Cell
Hide Keyboard When Scroll Uitableview
How to Draw a Circle in iOS Swift
How to Implement a Box or Gaussian Blur on iOS
Bundle.Main.Path(Forresource:Oftype:Indirectory:) Returns Nil
Weird Behaviour of Xcode 11 Debugger - Showing Values as Nil When There's a Value
Error: Uicollectionview Must Be Initialized with a Non-Nil Layout Parameter