I am new to Swift language. I've created a MapKit app that retrieves MKPointAnnotation
data (lat, log and title) recursively from a Sqlite DB (latest FMDB stack).
The purpose is to put a bunch of interest points on a MKMapViewDelegate
. I've tried w/out an array but the mapView.addAnnotation
overwrites any point and shows only the last one on the map, so I'm trying with an array.
I've create a function, but I get the error "fatal error: Cannot index empty buffer" in runtime when wpoint array is called.
Here's the code:
func initializeRoute()
{
sharedInstance.database!.open()
var resultSet: FMResultSet! = sharedInstance.database!.executeQuery("SELECT * FROM Route", withArgumentsInArray: nil)
// DB Structure
var DBorder: String = "order" // Int and Primary Index
var DBlatitude: String = "latitude" // Float
var DBlongitude: String = "longitude" // Float
// Array declaration
var wpoint: [MKPointAnnotation] = []
// Loop counter init
var counter: Int = 0
if (resultSet != nil) {
while resultSet.next() {
counter = counter + 1
wpoint[counter].coordinate = CLLocationCoordinate2DMake(
(resultSet.stringForColumn(String(DBlatitude)) as NSString).doubleValue,
(resultSet.stringForColumn(String(DBlongitude)) as NSString).doubleValue
)
wpoint[counter].title = resultSet.stringForColumn(DBorder)
mapView.addAnnotation(wpoint[counter])
}
}
sharedInstance.database!.close()
}
println ("Coordinate = \(wpoint.coordinate)")
show all data, I'm messing something within array declaration...