我试图在我的闭包中返回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
}
}
答案 0 :(得分:2)
关闭不是立即执行,而是在以后执行 - 因此返回某些内容是没有意义的。您应该在闭包内部使用用户位置(更新视图或其他内容)。