计算向mapView swift 4添加了多少自定义注释



我觉得这是一件简单的事情,我只是看得太多了。我有一个地图,用户按下按钮添加注释。

func addPinToPath() {
let catchPathPin = CatchAnnotation()
let catchLat = map.userLocation.coordinate.latitude
let catchLon = map.userLocation.coordinate.longitude
catchPathPin.coordinate = CLLocationCoordinate2D(latitude: catchLat, longitude: catchLon)
catchPathPin.title = "Fish On"
catchPathPin.subtitle = "Path"
catchPathPin.annoID = annoIDStart
catchPathPin.pinImageName = "catch"
let idToPass = catchPathPin.annoID
annoIDCatch = idToPass!
print(annoIDCatch)
map.addAnnotation(catchPathPin)
bitesInRoute = catchPathPin

}

在这一点上,我希望有一个计数器,显示添加了多少注释。

annotations.count会给我一个所有注释的计数,但我只想要CatchPathPin 的计数

有两个选项。您可以有一个每次递增的计数变量调用CCD_ 1。另一个选项是过滤当前注释并从中获取计数。

count = map.annotations
.filter { $0 is CatchAnnotation }
.count

最新更新