Yahyacode
Yahyacode

Reputation: 47

Can't return a variable in a closure swift

i am trying to return the userlocation variable in my closure but i can't . errror : unexpected a non void return value in void function I know i can't return an int because it's already returning -> Void but i can't change it to int because it's saving geoPointForCurrentLocationInBackground and everything .

@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

            }
}

Upvotes: 0

Views: 280

Answers (1)

Mario Zannone
Mario Zannone

Reputation: 2883

The closure is not executed immediately, but at a later time – so it does not make sense to return something. You should use the user location (to update the view or something) while inside the closure.

Upvotes: 2

Related Questions