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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With