How do you get your users City name when building a Weather app.

I'm am a coding novice in Swift UI and was wondering how weather apps find the name of the users current city? Could anyone point me in the direction of info how to do this task? Thanks,

need to get user location, which requires permissions, and then async geocode reverse lookup

https://stackoverflow.com/questions/68838081/updated-reverse-geolocation

I found this bit of code that done the trick:

 CLGeocoder().reverseGeocodeLocation(myLocation, completionHandler: {(placemarks, error) -> Void in

                            print(myLocation)

                            guard error == nil else {

                                print("Reverse geocoder failed with error" + error!.localizedDescription)

                                return

                            }

                        guard placemarks!.count > 0 else {

                                print("Problem with the data received from geocoder")

                                return

                            }

                        let pm = placemarks![0].locality

                        print(pm!)

                        myCity = (pm!)

                        print(myCity)

                        

                        })

How do you get your users City name when building a Weather app.
 
 
Q