我是Swift语言的新手。我创建了一个MapKit应用程序,它从Sqlite DB(最新FMDB堆栈)递归检索MKPointAnnotation
数据(经纬度,日志和标题)。Swift错误:致命错误:无法索引空缓冲区
目的是在MKMapViewDelegate
上放置一堆兴趣点。我已经尝试了w/out数组,但是mapView.addAnnotation
覆盖了任何点并仅显示了地图上的最后一个点,所以我尝试使用数组。
我已经创建了一个函数,但是当调用wpoint数组时,我在运行时遇到了错误“致命错误:无法索引空缓冲区”。
下面的代码:
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)")
显示所有的数据,我搞乱数组声明中的一些信息
谢谢Anna,我已经解决了重新声明Array:'var wpoint:Array = Array()',现在它可以工作! :) –
2015-01-10 16:49:31
我已经实施了你的建议,非常感谢! – 2015-01-10 17:03:22