從數組中刪除formattedCoordinate的適當命令是什麼?我知道一個removeObject存在Objective-C,但Swift怎麼樣?如何從Swift數組中刪除這個對象?
var markersArray: Array<CLLocationCoordinate2D> = []
func mapView(_ mapView: GMSMapView, didTap marker: GMSMarker){
let lat: CLLocationDegrees = marker.position.latitude
let lng: CLLocationDegrees = marker.position.longitude
var formattedCoordinate = CLLocationCoordinate2D(latitude: lat,longitude: lng)
//markersArray.remove(formattedCoordinate) need to fix this
self.clean()
// return 0; not sure if we need this here
}
func mapView(_ mapView: GMSMapView, didBeginDragging marker: GMSMarker){
let lat: CLLocationDegrees = marker.position.latitude
let lng: CLLocationDegrees = marker.position.longitude
var formattedCoordinate = CLLocationCoordinate2D(latitude: lat,longitude: lng)
// markersArray.remove(formattedCoordinate) need to fix this
}
棒的位置:在與刪除您行formattedCoordinate前 –
查看收藏迅速語種導遊部分:https://developer.apple.com/library /content/documentation/Swift/Conceptual/Swift_Programming_Language/CollectionTypes.html#//apple_ref/doc/uid/TP40014097-CH8-ID105 –
@ Konyv12 array.remove(at:Index)。提供索引值 –