I tried this to check the status of connectivity :
func checkConnection() {
if let url = URL(string: "https://www.xxxxxxxxxxxxxxxxxxxxx") {
var request = URLRequest(url: url)
request.httpMethod = "HEAD"
URLSession(configuration: .default)
.dataTask(with: request) { (_, response, error) -> Void in
guard error == nil else {
print("Error:", error ?? "")
return
}
guard (response as? HTTPURLResponse)?
.statusCode == 200 else {
print("down")
return
}
print("up")
}
.resume()
}
}
and it works fine. It shows "up" or "down" in console. I'm a beginner in Xcode and SwiftUI, so my question is: Instead of print("up") I want to go automaticly to the "ContentView" if URL is reachable. I tried ContentView() but it does not work.
Thanks for your help.