For some reason my segue is not being performed. Here is my storyboard setup.
This code is being called in viewDidAppear of my root view controller. In the XCode debugger it says that the fetch request returned 0 results before failing on the last line due to unexpectedly finding nil. If it returned 0 results, why wouldn't my segue be performed?
var fetchResult: [User] = []
do {
// Look for User entities in Core Data
fetchResult = try context.fetch(User.fetchRequest()) as! [User]
} catch {
fatalError("Fetch error")
}
if fetchResult.count == 0 {
// New user, calculate TDEE
performSegue(withIdentifier: "toTDEE", sender: self)
}
if fetchResult.count > 1 {
// ERROR: too many users
fatalError("fetch count > 1")
}
let user = fetchResult.first! as User