Hi everyone,
I'm working my way through the Apple Swift tutorial "FoodTracker" and everything works except the save data-part.
I think it's related to the unwindsegue that Apple wants me to use and XCode refuses to let me use.
The new meal/data is only supposed to be added when the save button is pressed and the unwindsegue sequence is used. However, this requires me to control-drag from my Save button to the Exit item, hereby linking my save button to the unwindToMealList function. And it doesn't work; nothing works. When ctrl-dragging, the Exit item isn't recognised, so I can't link to the function. From my searches, I can see I'm not the only one having this issue with XCode, but can't find a workaround.
So, my app is pretty much useless at the moment since I can only delete sample data, but not add anything new. I can press the save button all I want, but the view doesn't change as is the idea according to the tutorial.
I've thought about going without the unwindToMealList function / adapting it so the segue isn't required - + then add my own "back button" that doesn't require a segue but just goes back to my TableView and just letting Save handle the saving data-part.
Does anyone have any ideas on how to go about this?
My unwindToMealList function, in case anyone is interested - taken from the tutorial:
@IBAction func unwindToMealList(sender: UIStoryboardSegue) {
if let sourceViewController = sender.source as? MealViewController, let meal = sourceViewController.meal {
if let selectedIndexPath = tableView.indexPathForSelectedRow {
// Update an existing meal.
meals[selectedIndexPath.row] = meal
tableView.reloadRows(at: [selectedIndexPath], with: .none)
}
else {
// Add a new meal.
let newIndexPath = IndexPath(row: meals.count, section: 0)
meals.append(meal)
tableView.insertRows(at: [newIndexPath], with: .automatic)
}
}
}
Thanks!
/Steadi