[英]“Type of expression is ambiguous without more context” in Swift 3
我有MKMapView
類型的mapView
和地圖中的一些注釋。 我正在嘗試使用reduce計算此注釋的緯度中位數,但是我得到一個錯誤聲明:
沒有更多上下文的情況下,表達類型不明確。
這是我的代碼:
let medianLatitude = mapView.annotations.reduce( 0.0, { $0.coordinate.latitude + $1.coordinate.latitude })
使用reduce
,傳遞給閉包的第一個參數表示部分累加的結果。
在您的情況下,其類型需要匹配初始值0.0
它是Double
。
因此,請嘗試以下操作:
let medianLatitude = mapView.annotations.reduce( 0.0, { $0 + $1.coordinate.latitude })
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.