Im am passing an array of type CLLocationCoordinate2D from one controller to another.
However the user sometimes wont be passing any CLLocationCoordinate2D values which means the array in the next viewcontroller will be nil.
Currently Im stuck trying to safely unwrap the optional array and keep getting app crashes from the nil array so thought Id try and just initialize the array instead if no values are passed to it from the previous view controller.
So my array looks like this:
var favCoordinatesArray: [CLLocationCoordinate2D]?
but if I do this:
var favCoordinatesArray: [CLLocationCoordinate2D] = [(0.0, 0.0), (0.0, 0.0)]
Xcode complains and tells me I cant convert type CLLocationCoordinate2D to Doubles.
Im wondering if this will solve my problem.
regards J`
It is not difficult to initialize `CLLocationCoordinate2D`:
var favCoordinatesArray: [CLLocationCoordinate2D] = [CLLocationCoordinate2D(latitude: 0.0, longitude: 0.0), CLLocationCoordinate2D(latitude: 0.0, longitude: 0.0)]But you should better learn how to safely unwrap the optional array, it's the very basic part of Swift and you may need to know how to do if you continue to write an app in Swift.