I have an error with handling exceptions, and every time I open my app after the first launch, the app is terminated. My app is one where, once launched, data is inputted using a UI table view.
Is there a way to catch the error so that the app doesn't terminate? Please help.
Master View Controller:
override func viewDidLoad() {
super.viewDidLoad()
firstLaunchOfApp()
}
//MARK: - Check for first launch
func firstLaunchOfApp() {
let launchedBefore = NSUserDefaults.standardUserDefaults().boolForKey("launchedBefore")
if launchedBefore {
print("Not first launch.")
let index = NSIndexPath(forRow: 0, inSection: 0)
tableView.selectRowAtIndexPath(index, animated: false, scrollPosition: .Top)
pushNewValuesToDetail()
}
else {
print("First launch, setting NSUserDefault.")
NSUserDefaults.standardUserDefaults().setBool(true, forKey: "launchedBefore")
dispatch_async(dispatch_get_main_queue()) {
self.addNewCourseWork()
}
}
}
XCode Message:
Not first launch. 2016-05-11 16:27:45.530 CWCoreData[96559:855380] *** Terminating app due to uncaught exception 'NSRangeException', reason: '-[UITableView _contentOffsetForScrollingToRowAtIndexPath:atScrollPosition:]: row (0) beyond bounds (0) for section (0).'