Back | Forward
Chapter 7 of 10 at Apple Developer > Jump Right In is Implement Navigation.
Download the answer at the end of the chapter when you like.
One click for you, not two
Double-clicking the Navigation Item of the Meal Table View Controller never did work for me, despite all Apple says.
I had to click it once to select it in the Outline View, then visit the Attributes Inspector, then type out Your Meals as its Title.
<= Learning Objectives
<= Add a Segue to Navigate Forward
<= Configure the Navigation Bar for the Scenes
Far enough below, you must know
Apple says "below the else statement" to mean below the "else" and below the "return" and below the "}" that the guard-let-else statement ends with.
guard let button = sender as? UIBarButtonItem, button === saveButton else {
os_log("The save button was not pressed, cancelling", log: OSLog.default, type: .debug)
return
}
// <= "BELOW THE ELSE" MEANS HERE
let name = nameTextField.text ?? ""
<= Store New Meals in the Meal List
<= Create an Unwind Segue
Talk like a lawyer or not
Impress your friends! Learn to name a thing the "nil coalescing operator"!
Or spend your time more usefully.
Up to you. Apple is trying to talk about the idea of "or else a default value". If you've supplied a Nil value, then the ?? "" is a syntax meaning take an Empty String instead.
If you think you shouldn't have to learn the difference between Nil and an Empty String, you're right, but you won't get out of learning such a thing, not in our day and time. You will get out of remembering what a "nil coalescing operator" is, if you just try.
<= Create an Unwind Segue
Trust the FixIt when you should
Apple tells me their source should work, but it doesn't. I'd guess they made a copy-paste error of some kind.
So long as I understand enough of why the FixIt's inside Xcode make the decisions they make, then I can judge when to accept their changes or not, and then I end up with code that works, such as:
@IBAction func unwindToMealList(sender: UIStoryboardSegue) {
if let sourceViewController = sender.source as? MealViewController, let meal = sourceViewController.meal {
<= Create an Unwind Segue
Ouch so many buttons
Refusing to let Save button take the text until after you press Done? That makes no sense.
Insisting on text but not insisting on a rating or a photo? That makes little sense.
Happily, these illogical inconsistencies don't have to stop you from learning. You can just move on, or figure out how to fix them and tell us.
<= Disable Saving When the User Doesn't Enter an Item Name
<= Cancel a New Meal Addition
Some stars more equal than others
As I practice these exercises, I find I frequently did long ago forget to tell the Attributes Inspector of the Content View of the MealTableViewCell to turn off User Interaction Enabled.
If clicking on the stars changes the rating, that's why, and that's how to fix it.
<= Wrapping Up
Download and compare and commit