[英]Why can't Swift closure variable types be implicitly unwrapped optionals?
[英]Can't return a variable in a closure swift
我試圖在關閉時返回userlocation變量,但是我不能。 錯誤:意外的void函數中的非void返回值,我知道我無法返回int,因為它已經在返回-> Void,但是我無法將其更改為int,因為它正在保存geoPointForCurrentLocationInBackground和其他所有內容。
@IBAction func add(sender: UIButton) {
PFGeoPoint.geoPointForCurrentLocationInBackground {
(userlocation: PFGeoPoint?, error: NSError?) -> Void in
if let point = userlocation where error == nil {
println(point.latitude)
println(point.longitude)
//let point = userlocation
var userlocation = PFGeoPoint(latitude: point.latitude, longitude: point.longitude)
}
return userlocation
}
}
閉包不會立即執行,而是在稍后的時間執行-因此返回某些內容沒有意義。 在閉包內部時,應使用用戶位置(以更新視圖或其他內容)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.