Friday, November 24, 2017

Where to Go from Here

Back | Forward


Chapter 10 of 10 at Apple Developer > Jump Right In is Where to Go from Here.


Where to go from here!

Great question, sure. Tell us if you got this far? Is your first app working for you? What will you do next?


Back | Forward | Source: Apple Developer > Where to Go from Here

Persist Data

Back | Forward



Chapter 9 of 10 at Apple Developer > Jump Right In is Persist Data.

Download the answer at the end of the chapter when you like.



Again not corrected when written

Yea, they really do walk you thru editing a few things before telling you if you got them right or not.

Oh well.

<= Learning Objectives
<= Save and Load the Meal

<= Save and Load the Meal List


Less structure when tired


Here at the end of the lessons, Apple throws the last pile of steps at you without much visible structure. Not enough subdivision of the chapter. One pair of headings that start with the same five words before marking one is different just by adding a sixth word.

Oh well.

<= Save and Load the Meal
<= Save and Load the Meal List


Download and compare and commit


The download is 09_PersistDataYour Commit Message can be "Persist Data". 

<= Wrapping Up


Back | Forward | Source: Apple Developer > Persist Data

Implement Edit and Delete Behavior

Back | Forward



Chapter 8 of 10 at Apple Developer > Jump Right In is Implement Edit and Delete Behavior.

Download the answer at the end of the chapter when you like.



Too few words


The "Show" of Selection Segue is not the "Show" of the Accessory Action. You must watch closely enough to never confuse those two.

<= Learning Objectives
<= Enable Editing of Existing Meals




Not quite as quoted


You'll find "override func prepare(for segue: UIStoryboardSegue, sender: Any?) {" when you go looking for "override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {".

<= Enable Editing of Existing Meals


Not corrected when written


Yea, they really do walk you thru editing the "tableView(_:commit:forRowAt:)" method without showing you what that first edit should look like, so that then they can detour you thru a second edit of the "tableView(_:canEditRowAt)", so that only then can they remember to get around to showing you what the first edit should look like.

Oh well.

<= Cancel an Edit to an Existing Meal
<= Support Deleting Meals


Download and compare and commit


The download is 08_ImplementEditAndDeleteBehaviorYour Commit Message can be "Implement Edit and Delete Behavior". 

<= Wrapping Up


Back | ForwardSource: Apple Developer > Implement Edit and Delete Behavior.


Sunday, November 19, 2017

Implement Navigation

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


The download is 07_ImplementNavigationYour Commit Message can be "Implement Navigation". 

<= Wrapping Up


Back | Forward | Source: Apple Developer > Implement Navigation


Create a Table View

Back | Forward



Chapter 6 of 10 at Apple Developer > Jump Right In is Create a Table View.

Download the answer at the end of the chapter when you like.

You know enough now that you might win through quickly without our advice, you can just try the chapter.



Squaring the star


The stars didn't come out square for me.

I like small phones, because small, so I target the iPhone 5s in simulation.

On such a small screen, to get the stars to come out with the same horizontal-vertical that I put in, I had calculate what Utilities > Size Inspector I wanted.

Working with 5 of the 44x44 buttons at a Spacing of 1 made for a Width of 224 == ((5 * 44) + (4 * 1)).

<= Learning Objectives
<= Create the Meal List
<= Design Custom Table Cells




Yea they left it nameless


Why do they name an "override func" with the noun "tableView" rather that a verb to say what it does?

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return meals.count


    }

I have no idea.

I imagine that decision won't make much sense until after you and I learn some more abou the Swift programming language, and even then we might find this to be sloppy work. Somehow it made sense to them to start out with the excessively abbreviated "override func tableView".

&lt;= Add Images to Your Project
<= Connect the Table Cell UI to Code
<= Load Initial Data
<= Display the Data



Download and compare and commit


The download is 06_CreateATableViewYour Commit Message can be "Create a Table View". 

<= Wrapping Up


Back | Forward | Source: Apple Developer > Create a Table View

Thursday, November 9, 2017

Define Your Data Model

Back | Forward



Chapter 5 of 10 at Apple Developer > Jump Right In is Define Your Data Model.

Download the answer at the end of this chapter whenever you like.



No you don't need to be them any time soon


Yea, they really do tell you to read and understand all of the voluminous "FoodTrackerTests.swift" file, even though they then tell you to delete most of what you just deciphered.

So you might rather delete what you're going to delete, then go back and understand just what remains.

<= Learning Objectives
<= 
Create a Data Model

<= Test Your Data


Always the pieces, sometimes the whole


Yea there's a glaring tupo of an entire example missing at <<< Your unit test class should look like this: >>>. In place of the example, they give you only its first line. Oh well. What they meant to say is, in order to demo your first test failure, your code should look like this:
import XCTest
@testable import FoodTracker

class FoodTrackerTests: XCTestCase {
    
    //MARK: Meal Class Tests
    
    func testMealInitializationSucceeds() {
        
        let zeroRatingMeal = Meal.init(name: "Zero", photo: nil, rating: 0)
        XCTAssertNotNil(zeroRatingMeal)
        
        let positiveRatingMeal = Meal.init(name: "Positive", photo: nil, rating: 5)
        XCTAssertNotNil(positiveRatingMeal)
    }
    
    func testMealInitializationFails() {
        
        let negativeRatingMeal = Meal.init(name: "Negative", photo: nil, rating: -1)
        XCTAssertNil(negativeRatingMeal)
        
        let largeRatingMeal = Meal.init(name: "Large", photo: nil, rating: 6)
        XCTAssertNil(largeRatingMeal)
        
        let emptyStringMeal = Meal.init(name: "", photo: nil, rating: 0)
        XCTAssertNil(emptyStringMeal)
    }
}
<= Test Your Data


Simulate an iPhone to fail your first test


Yes, testing your code as they suggest will trigger Xcode to open up a simulated iPhone, if you have quit Xcode and relaunched it since you last needed to run a simulated iPhone.


This launch will be as slow as it always is, first negotiating your admin privilege to do such a thing, and then taking time for the simulated iPhone to boot. But they will eventually get around to testing the code of your Data Model.


<= Test Your Data


Download and compare and commit


The download is 05_DefineYourDataModelYour Commit Message can be "Define Your Data Model". 



<= Wrapping Up



Back | Forward | Source: Apple Developer > Define Your Data Model

Sunday, November 5, 2017

Implement a Custom Control

Back | Forward



Chapter 4 of 10 at Apple Developer > Jump Right In is Implement a Custom Control.


This is another chapter that never tells you, just expects, that you will start by jumping to the end of it and downloading a folder with an Images folder inside of it, so you can borrow those Png images when you need them.


The Fix-It buttons help


The newer versions of Xcode get more right by default. Don't expect Apple's guess of how much you need to fix to be correct. Just focus on taking the coding suggestions from Xcode.


<= Learning Objectives
<= Create a Custom View


Watch the Outline View closely


Apple means to ask you to land your Horizontal Stack View that becomes Rating Control at the bottom inside the UIStackView that vertically stacks your Meal Name Label, Name Text Field, and Photo Image View.

They never quite get around to asking for this out loud. Your results will match theirs much more closely if you pick up on this point. 

<= Display the Custom View


Match dimensions


Your Storyboard and App will look more like Apple's if you tell Utilities > Size Inspector to make your Horizontal Stack view have Width = 252 and Height = 44. That's because they're working with 5 of the 44x44 buttons at a Spacing of 8, and 252 == ((5 * 44) + (4 * 8)).

<= Add Buttons to the View


Help Interface Builder sketch your app


Do work thru adding support for Interface Builder, even though all that's wrong before you do is an inaccurate Storyboard, none of the errors and warnings that Apple explains used to haunt us.

<= Add Support for Interface Builder
<= Add Star Images to the Buttons


Keep the prints


You can keep the print statements, they trace what happens, they do no harm.

You'll have to keep the "@objc" fix-it for "func ratingButtonTapped", the code won't build otherwise.

The call to "updateButtonSelectionStates" from "setupButtons" isn't needed and does no harm.

<= Implement the Button Action


Try a real phone


The iPhone Simulator doesn't demo Settings > General > Accessibility > VoiceOver. You need a real phone for that, until we can get Apple to make more of a commitment to Accessibility.

To try a real phone, you need a friend with an Apple Developer subscription. US$100 per year plus tax was the cost to your friend, as of 2017.

<= Add Accessibility Information


Cooperate



Apple throws some more chores in here at random for you, not yet needed, but useful later. You may as well go along.

<= Connect the Rating Control to the View Controller
<= Clean Up the Project



Don't test Landscape View now


Apple doesn't mention that you've made only the portrait view work. You've broken the landscape view for devices smaller than an iPad.

Don't worry about it. You'll fix it soon enough.

<= Wrapping Up

 

Download and compare and commit



The download is 04_ImplementACustomControlYour Commit Message can be "Implement a Custom Control". 

<= Wrapping Up



Back | Forward | Source: Apple Developer >
 Implement a Custom Control