I am getting the error:
objc[12772]: Cannot form weak reference to instance (0x137d65240) of class appName.ViewController. It is possible that this object was over-released, or is in the process of deallocation.
I find this strange because this happened only after I have added a button click to bring the user to this UIViewController through instantiation. After running the app again, the error goes away so this occurs only when the user is segued into this UIViewController from a button.
Does anyone have any idea as to what causes this issue?
@IBOutlet weak var time: UILabel!
@IBOutlet private weak var startPause: UIButton! {
didSet {
startPause.setBackgroundColor(.green, for: .normal)
startPause.setBackgroundColor(.yellow, for: .selected)
startPause.setTitle("PAUSE".uppercased(), for: .selected)
}
}
private lazy var stopwatch = Stopwatch(timeUpdated: { [weak self] timeInterval in // SIGNAL SIGABRT
guard let strongSelf = self else { return }
strongSelf.time.text = strongSelf.timeString(from: timeInterval)
})
deinit {
stopwatch.stop()
}
@IBAction func toggle(_ sendler: UIButton) {
sendler.isSelected = !sendler.isSelected
stopwatch.toggle()
}
@IBAction func reset(_ sendler: UIButton) {
stopwatch.stop()
startPause.isSelected = false
}
private func timeString(from timeInterval: TimeInterval) -> String {
let seconds = Int(timeInterval.truncatingRemainder(dividingBy: 60))
let minutes = Int(timeInterval.truncatingRemainder(dividingBy: 60 * 60) / 60)
let hours = Int(timeInterval / 3600)
return String(format: "%.2d:%.2d:%.2d", hours, minutes, seconds)
}
Code To Present View Controller:
class TutorialViewController: UIViewController {
@IBOutlet weak var doneTut: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func doneTut(_ sender: Any) {
let homeViewController = self.storyboard?.instantiateViewController(identifier: Constants.Storyboard.homeViewController) as? HomeViewController
self.view.window?.rootViewController = homeViewController
self.view.window?.makeKeyAndVisible()
}
}