I have two floats to be sent to my destination controller in a prepareForSegue function. I have my variables set up in both variables but I am encountering the above error.
if segue.identifier == "secondmapsegue"
{
let destination = segue.destination as! MapsView
let indexPath = tableView.indexPathForSelectedRow
var lat: Float
var long: Float
if index.row == 0 {
lat = MSULandMarks[(indexPath?.row)!].f1
long = MSULandMarks[(indexPath?.row)!].f2
}
else if index.row == 1 {
lat = MSUFrats[(indexPath?.row)!].f1
long = MSUFrats[(indexPath?.row)!].f2
}
else
{
lat = MSUSoro[(indexPath?.row)!].f1
long = MSUSoro[(indexPath?.row)!].f2
}
destination.latitude = lat
destination.longitude = long
}
override func viewDidLoad() {
super.viewDidLoad()
var latitude: Float
var longitude: Float
Update 1: The solution selected below was the solution! The slight confusion on my end was the the Xcode suggestion of adding an intial value to the latitude and longitude in my destination controller like so,
var latitude: Float = 0.0
var longitude: Float = 0.0
Don't fret, simply accept the recommendation and continue with your project. Assuming your lat. and long. have values, the 0.0 values will be replaced with your real values.
I assume that the following snippet is from the destination controller MapsView
:
override func viewDidLoad() {
super.viewDidLoad()
var latitude: Float
var longitude: Float
}
You need to declare your variables outside your viewDidLoad
function, like this:
var latitude: Float
var longitude: Float
override func viewDidLoad() {
super.viewDidLoad()
}