structSomeStructure {funcsomeFunction() {// if internet available proceed else returnguard InternetChecker.shared.internetIsAvailable else { return }// do something when internet is available. }
Source files are as follows.
InternetChecker.swift
publicenumInternetError:Error{case noInternet}publicstructInternetChecker {privateinit() {}publicstaticvar shared =InternetChecker()publicvar internetIsAvailable: Bool {let status =Reach().connectionStatus()switch status {case .unknown, .offline:returnfalsecase .online(.wwan):returntruecase .online(.wiFi):returntrue } }}