Please tell me if I am doing something wrong.

I want to determine if I am within a 10m radius of an area on my iphone's location information, but when I wait for the result and then go to the next process, the result of the inside/outside determination does not come back. Please tell me if I am doing something wrong.

    func SpotArea_judgment(place: String, rad: Int, location:CLLocationCoordinate2D) -> Bool? {

        var result: Bool?
        let semaphore = DispatchSemaphore(value: 0)
        let geocoder = CLGeocoder()
        geocoder.geocodeAddressString(place) { (placemarks, error) in
            let center = CLLocationCoordinate2D(
                latitude: Double(placemarks?.first?.location?.coordinate.latitude ?? 0),
                longitude: Double(placemarks?.first?.location?.coordinate.longitude ?? 0)
            )
            let radius: CLLocationDistance = Double(rad)
            let circularRegion = CLCircularRegion(center: center, radius: radius, identifier: "identifier")
            result = circularRegion.contains(location)
            semaphore.signal()
        }
        semaphore.wait()
        return result
    }

result of the inside/outside determination does not come back

What do you mean ? It comes back wrong ? You stay in a dealock ?

May be you could run in a different thread and use a completion block instead of a return value from the func.

See example here (in a different context, but same pattern).

https://stackoverflow.com/questions/34861337/wait-for-async-function-return-value-in-swift

Did you look at async/wait pattern instead of semaphore ? That's the new way to do it.

Please tell me if I am doing something wrong.
 
 
Q