从数组中删除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)。提供索引值 –