Group Group Group Group Group Group Group Group Group

Return a 2D Array from a Func

Can anyone let me know what i can do here to return a 2D array? From this below i get: Consecutive declarations on a line must be separated by ‘;’ Thank you

func findLocationsForEachRange() -> [[Double]] {
//var myCount = myLocations.count
var locationsVisitedLatLong: [[Double]] = []
for myLocation in myLocations {
if (myLocation.date! >= WeeklySpan(increment: myValue)) {
locationsVisitedLatLong.append(contentsOf: [[myLocation.latitude, myLocation.longitude]])
}
}
}return locationsVistedLatLong[[Double]]

Hi @flmcl,
You already have the result array locationsVisitedLatLong as the outer array of type [[Double]]

Now, when you are appending, you need to append to this array only what you need, which is an array of Doubles, not an Array of Array of Doubles.

so, change your append to

locationsVisitedLatLong.append([myLocation.latitude, myLocation.longitude])

However, a small tip, I don’t know the reason for you using this particular structure, lat lon generally come in pairs, so instead if you use a tuple or a struct, you can have a simple array of lat/longs and manage them easier.

Cheers,

1 Like

This topic was automatically closed after 166 days. New replies are no longer allowed.