Categories
ios swift

Check if internet connection availabile in swift

Is there an Apple framework bundle to detect if there’s an internet connection? Currently my application crashes when it tries to geolocate the user’s position without an internet connection.

/*inside locationManager didUpdateLocations method*/
var currentLocation:CLLocation? = locations[0] as? CLLocation
geocoder = CLGeocoder()
//Crashes on line below when there isn't an internet connection
//Need to add function to check if internet connection is live
//Before running reverseGeocodeLocation
geocoder.reverseGeocodeLocation (currentLocation,handleGeocode)

I’m a bit new to swift and ios programming – my apologies.