Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compiler error: "Consecutive statements on a line must be separated by ;"

Tags:

swift

I am getting an error after adding the bottom line of code in this screenshot. Closing out and restarting Xcode did nothing and I really want to know what I'm doing wrong.

I apologize for asking what will probably be a simplistic question but I am new to coding with Swift.

I did have a problem importing CoreLocation as it did not auto populate like I thought it would. It seems that problem might directly relate to this one.

clipped screenshot of code

like image 449
Kelly Mayo Avatar asked Sep 02 '25 04:09

Kelly Mayo


1 Answers

That's not valid Swift syntax. The colon indicates the fact that you want to declare a variable/property, while the parentheses indicate that you want to create a new value, and values must be assigned via the equal character.

You should instead be writing

var locationManager = CLLocationManager()

as Swift will infer the appropriate type if it can.

Or, if your want to also specify the type

var locationManager: CLLocationManager = CLLocationManager()

or, if you want to simply declare it:

var locationManager: CLLocationManager

however, you'd better make it a let if you don't plan to change it:

let locationManager = CLLocationManager()

as let is always preferred in the first instance over var - i.e. declare the variable as let and change it later to var if needed.

like image 121
Cristik Avatar answered Sep 05 '25 00:09

Cristik