Swift kann nicht zugewiesen unveränderliche Wert des Typs [CLLocationCoordinate2D]

Kann mir jemand erklären, warum ich die Fehlermeldung "cannot assign unveränderlich Wert vom Typ [CLLocationCoordinate2D]" ich gebe zwei Szenarien. Der Grund ich will die zweite Arbeit ist, denn ich wäre in einer Schleife und müssen übergeben, die drawShape func jeder Zeit.

Dieser code funktioniert:

func drawShape() {
    var coordinates = [
        CLLocationCoordinate2D(latitude: 40.96156150486786, longitude: -100.24319656647276),
        CLLocationCoordinate2D(latitude: 40.96456685906742, longitude: -100.25021235388704),
        CLLocationCoordinate2D(latitude: 40.96528813790064, longitude: -100.25022315443493),
        CLLocationCoordinate2D(latitude: 40.96570116316434, longitude: -100.24954721762333),
        CLLocationCoordinate2D(latitude: 40.96553915028926, longitude: -100.24721925915219),
        CLLocationCoordinate2D(latitude: 40.96540144388564, longitude: -100.24319644831121),
        CLLocationCoordinate2D(latitude: 40.96156150486786, longitude: -100.24319656647276),
    ]
    var shape = MGLPolygon(coordinates: &coordinates, count: UInt(coordinates.count))
    mapView.addAnnotation(shape)
}

Dieser code funktioniert NICHT:

override func viewDidLoad() {
    super.viewDidLoad()

    //does stuff
    var coords: [CLLocationCoordinate2D] = [
            CLLocationCoordinate2D(latitude: 40.96156150486786, longitude: -100.24319656647276),
            CLLocationCoordinate2D(latitude: 40.96456685906742, longitude: -100.25021235388704),
            CLLocationCoordinate2D(latitude: 40.96528813790064, longitude: -100.25022315443493),
            CLLocationCoordinate2D(latitude: 40.96570116316434, longitude: -100.24954721762333),
            CLLocationCoordinate2D(latitude: 40.96553915028926, longitude: -100.24721925915219),
            CLLocationCoordinate2D(latitude: 40.96540144388564, longitude: -100.24319644831121),
            CLLocationCoordinate2D(latitude: 40.96156150486786, longitude: -100.24319656647276),
        ]

    self.drawShape(coords)
}

func drawShape(coords: [CLLocationCoordinate2D]) {
    var shape = MGLPolygon(coordinates: &coords, count: UInt(coords.count)) //---this is where the error shows up
    mapView.addAnnotation(shape)
}

Verstehe ich nicht, warum dies nicht funktioniert. Ich habe auch println(coordinates) vs println(coords) und es gibt mir die gleiche Ausgabe für jeden.

InformationsquelleAutor thinkgeekguy | 2015-07-08

Schreibe einen Kommentar