2

私はSwift言語が初めてです。MKPointAnnotationSqlite DB (最新の FMDB スタック) からデータ (緯度、ログ、タイトル) を再帰的に取得する MapKit アプリを作成しました。

目的は、 に多数の関心点を置くことMKMapViewDelegateです。配列なしで試してみましたが、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)")すべてのデータを表示します。配列宣言内で何かを台無しにしています...

4

1 に答える 1