When I launch the simulator, a black screen appeared! Same with an error saying "Thread 1: signal SIGABRT" in AppDelegate. Lastly, an error in the right hand corner tells me that they could not load NIB in bundle. I'm also new at coding, so I still have a lot to learn. If you like you can give me some tips. Here's my code if you need to take a look:
import UIKit
class ViewController: UIViewController {
public var screenWidth: CGFloat {
return UIScreen.main.bounds.width/100
}
var thereIsInternet:Bool?
var reachability:Reachability?
var numberTowardCompletion = 0
override func viewDidLoad() {
super.viewDidLoad()
barProgress.frame.size.width = 0
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
barProgress.frame.size.width = 0
self.reachability = Reachability.init()
if ((self.reachability!.connection) != .none) {
thereIsInternet = true
} else {
thereIsInternet = false
}
let when = DispatchTime.now() + 5
DispatchQueue.main.asyncAfter(deadline: when) {
}
}
@IBOutlet weak var barProgress: UIView!
@IBOutlet var percent: UILabel!
@IBOutlet var loading: UILabel!
func checkingInternet() {
if thereIsInternet == true {
loading.text = "Internet is present"
barProgress.frame.size.width = screenWidth * CGFloat(15)
} else {
loading.text = "ERROR"
let alert = UIAlertController(title: "Connection Problem", message: "Make sure you're connected to the internet", preferredStyle: .alert)
let restartAction = UIAlertAction(title: "Restart", style: .default, handler: { (UIAlertAction) in
self.startOver()
})
alert.addAction(restartAction)
present(alert, animated: true, completion: nil)
}
}
func startOver() {
barProgress.frame.size.width = 0
self.reachability = Reachability.init()
if ((self.reachability!.connection) != .none) {
thereIsInternet = true
} else {
thereIsInternet = false
}
let when = DispatchTime.now() + 5 // change 2 to desired number of seconds
DispatchQueue.main.asyncAfter(deadline: when) {
}
checkingInternet()
}
}
Try this in Appdelegate where ViewControllerHere is the name of the viewcontroller xib file
self.window.rootViewController = ViewController(nibName: "ViewControllerHere", bundle: nil)