Sunday, November 5, 2017

Connect the UI to Code

Back | Forward



Chapter 2 of 10 at Apple Developer > Jump Right In is Connect the UI to Code.



Don't need much vocabulary


Apple pushes hard for you to struggle to learn what all their words mean.

This is silly. They're flooding you with words you don't need. Xcode itself is tightly limiting your options. You can work all the way thru to the end and push out a well-running app without ever having made time to understand what a "superview" is, or "an implicitly unwrapped optional variable", and so on and on.

You really can focus on what they tell you to do, and learn what it means by watching what happens. Their diagrams do help. Their explanations in words aren't worth much. I'm here to argue most of their explanations in words aren't even worth reading, much less deciphering.

Apple mentions many technical terms you will learn someday, as if you need them now




Model, view, and controller


Xcode divides your app into three parts. Apple runs you on in without quite pausing to tell you this. The picture their authors have in mind as they speak is something like Wikipedia Model view controller.

Apple gives no definition for the few technical terms you do need now


<= Learning Objectives
<= Connect the UI to Source Code




Editor and Assistant Editor


Apple is trying to say that you often want to edit two things at a time, instead of just one.

That's it, that's all they mean, even though they go on and on.

For instance, all at once, you want to look at a Storyboard and also the Swift code running inside it. Well sure, you do. When they say "The Editor", they mean where you mess with the first thing you opened. When they say "The Assistant Editor", they mean where you mess with the second thing you opened.

You find the correct X to close the Assistant Editor.

You find the Pair of Overlapping Hoops to open the Assistant Editor, and notice they turn blue while it's open, and notice that opening the Assistant Editor gives you a second Pair of Overlapping Hoops just above whatever you're editing inside the Assistant Editor.

It's that second Pair in grey that sit next to some Triple Dots "..." in grey. It's those Triple Dots of that second Pair that give you an "Automatic" choice telling you what they guess the second thing should be to edit inside the Assistant Editor, after you select some first thing to edit inside the Editor.

Apple has forgotten the courtesy of drawing a new icon for each new thing


<= Create Outlets for UI Elements




Marks in the code


Apple tells you out loud that they want you to learn to make Marks before they show you what good they are.

Wow. Well, me, I find people giving mystic orders difficult to accept. If you like, go ahead and make three marks in the same file, so you can see how they work.

Before now, you've already found your grey Pair of Overlapping Hoops, and the Triple Dots just to the right of those. Now you can look out to the right end of that chain where you're told what Class you have selected inside the Assistant Editor. Click there to see all the Marks you have made inside that Class, and then click on a Mark to warp to it.

Apple has lost the discipline of introducing the new thing no sooner than it matters

<= Create Outlets for UI Elements



Drag it from where you can find it


Apple talks as if people always only Ctrl+Drag from the Storyboard into Swift.

Yea maybe. The thing is, you can look at two places on screen to see what you select inside the Storyboard. You can look at the Storyboard itself, your mock-up of an iPhone. But you can also look at the Document Outline on the left that shows all its pieces as a list of lists of lists of things, unless you've accidentally hit the Hide/Show Document Outline button to hide it.

And once you've learned to select things inside the Document Outline, you'll often find that easiest to hit with the mouse, select, and Ctrl+Drag from.

Apple introduces two in tandem by talking about one and ignoring the other

<= Create Outlets for UI Elements


One word and two


Apple pushes you to define a "mealNameLabel" and a "nameTextField".

They neglect to disclose the deeper structure of those choices. The structure is obvious only after you learn, and then still rudely hard for a new person to remember because of the choices they made.

The "mealNameLabel" is a first name of two words and a last name of one word: it is a "Label" that presents the "mealName".

The "nameTextField" is a first name of one word and a last name of two words: it is a "TextField" that presents the "name" of the meal. Indeed, one might say it is a "mealNameTextField", if giving your students all the consistency you can were a priority.

Apple has chosen example names so poorly as to trip up new people

<= Create Outlets for UI Elements




Don't trust every kind of undo


This is the place in the tutorial where learning to undo well really begins to matter. For example, near here, you may need Source Control > Discard All Changes, which should just send you back to the start of this chapter, if you ended the last chapter with a Source Control > Commit that worked.

Here now, if you misunderstand just enough to move ever so slightly off the one true path, like you accidentally make an IBOutlet where you wanted an IBAction, well, that's crazy hard to undo. You can undo everything you can see, without it really being undone inside, in the details that only "git diff" shows.

And while it's not really undone, your app will crash, yammering on about some mystic wound such as "NSInvalidArgumentException" "unrecognized selector sent to instance".

You can quickly back out, start over, and get it right.

Apple has forgotten to make your every likely error visible

<= Define an Action to Perform
<= Process User Input




Download and compare and commit


Apple ends this chapter, its chapter 2 of 10, with a download named "02_ConnectTheUIToTheCode". They're just meaninglessly sloppy, inserting an extra "the" into that name that's missing from this chapter's title.

Apple mentions the download & forgets to recommend compare at the end of each chapter.

As soon as you're sure you're finished with this chapter, you can capture your progress. Click back on thru Xcode > Source Control > Commit. Give it a Commit Message such as "Connect the UI to Code". Click to Commit Files. Be happy.

<= Wrapping Up


Back | Forward | Source: Apple Developer > Connect the UI to Code

No comments: