Sunday, October 29, 2017

Build a Basic UI

Back | Forward



Chapter 1 of 10 at Apple Developer > Jump Right In is Build a Basic UI.


Hope for a bot to think with


Apple picks a first goal for your app: it must learn to listen, to speak, and to act.


You tell your app to listen inside its UITextField, you tell it to speak out thru its UILabel, you tell it to act when some human taps its UIButton.


Apple leads with the sneer of "Basic" and the alphabet soup of "UI", but they mean well


<= Learning Objectives




Find the answers in the back of the book


Each chapter of the tutorial ends with a copy of Apple's solution. Glance into it as often as you want, to compare their solution with yours.

You can open the project folder in Xcode, or its '.xcodeproj' file, or compare the text of the files of one project with another

<= Learning Objectives


Don't replace all the example texts


Apple means to say you should create some new folder to work with Xcode, such as "~/Documents/Xcode-Projects". Inside that folder you place your Xcode Projects. Each Project is its own Git Repo.


Apple means to say you can leave the Organization Identifier set to "com.example". They don't mean to say you must spell your own name backwards, as with "org.ieee.doe.jq".


Apple means to say you can give no Organization Name at all, you don't have to name yourself as an organization, you don't have to name some other organization.


Curiously, Apple prints no copyright claims into your code if you name no organization. If you do name an organization, then Apple puts claims into your code to say you assigned your copyrights to them.

Apple doesn't invite you to claim copyright and doesn't applaud you giving anonymously


<= Create a New Project

<= Get Familiar with Xcode



Pick one iPhone to simulate


Beware, Xcode will leave stale versions of your app behind on every iPhone you simulate.

That gets wildly confusing if you try more than one iPhone. Xcode will frequently slap you back into choosing its default choice. Either you take its default as mandate, or you learn to delete old versions of your app.

Xcode shrugs off much of the work of distributing your apps under test

<= Run iOS Simulator


Expect to start twice


Apple develops Xcode with all its security turned off.

If you're typing a password every time you restart Xcode, you're working harder than they do, and you'll notice that your first launch of the iPhone Simulator fails, because you didn't type out your password in zero time. No big deal, once you understand. You just start again.



Xcode doesn't encourage you to aggressively defend your own MacBook



<= Run iOS Simulator


Watch your iPhone simulation catch up


The first iPhone that Xcode shows you won't look the same at first as it does later. Xcode lets you run ahead and get started even as it is slowly slowly filling out the phone for the first time. It is busy installing a dozen apps alongside yours, you just don't get that news unless you ask for it.

Apple forgets to tell you how it is disrupting your world

<= Run iOS Simulator


Race ahead


Apple invites you to review the "AppDelegate.swift" file, as if that file contained words you would find pertinent as you work thru this tutorial. It doesn't. You can skip it.

Apple forgets to respect your time intensely

<= Review the Source Code
<= The App Delegate Source File


Walk backwards


Apple has somehow chosen to come off as arrogantly imagining their words are perfect. They say just tell you, yea, you do what we meant to tell you, without ever walking you thru how to undo any misunderstandings. As if that could ever be real.

So early on, find your way to the major kinds of Undo that work better than:
Edit Undo        ⌘Z
Experiment with:
Product > Clean        ⇧⌘K 
Yea I mean it        ⌥⇧⌘K 
Push so hard as to learn the destructive:
Source Control > Discard All Changes
You'll have to redo what you just did when you try that, but it's worth it, because here you learn how to undo what you did wrongly by accident, when you don't even know what it was that you did wrong.

If you know Git, you can Quit Xcode, drop down into the Terminal, and learn to destroy the rest of your changes like so:
git log 
git reflog
git status --short --ignored 
git clean --ffxdq
That extreme technique for destroying all your work is even more thorough than the choices Xcode gives you. That sharp scalpel will likely go wrong if you forget to quit Xcode or if you haven't already learned Git. For instance, that sharp scalpel will delete all new files.

Apple has forgotten the courtesy of always inviting you to undo what they misunderstood

<= The View Controller Source File
<= Open Your Storyboard


Notice Editor is not Edit


Yes, it's true, Xcode has one menu named "Editor" and another named "Edit", just to feed the pain of all humans who find those two words extremely similar.

Likewise, this very tutorial has this entire chapter named "Build the Basic UI" and also a subchapter also named "Build the Basic UI", as if naming a child after a parent.

Apple has forgotten the courtesy of giving totally different names to totally different things

<= Build the Basic UI


Distrust enough defaults


Editor > Canvas > Show Bounds Rectangles will shut off and stay off till you discover it.

Did you catch that? Xcode will choose to turn things off that you need before you discover they exist.

Xcode neglects its duty to give first preference to the newest guest

<= Build the Basic UI


Frequently correct the Zoom


Xcode frequently requires you to rework its zoom. They hide that choice inside of Editor > Zoom > Zoom To Fit. You can also find it if you right-click. You may notice there is a Zoom control you can click into, but it just gives you hard numbers like "75%", it rudely neglects to offer "fit".

Apple does think hard enough and talk long enough to mention you might need to zoom in, but they neglect to mention you often want to zoom to fit and you sometimes want to zoom out.

Xcode doesn't volunteer to show you what you need to see

<= Build the Basic UI


Expect Xcode will be slow to hear you


As often as they tell you press the Return key after you change something, they really mean it. Xcode can sit for hours without taking notice of your input, unless you make a point of pressing Return or clicking to highlight a different input.

Xcode doesn't limit how long it ignores you

<= Build the Basic UI


Let Apple waste some time


Apple pushes you into the Assistant Editor Preview as if it were useful.

It's not useful yet, but it will be useful. Take this one on faith. You'll soon learn to choose from a series of previews. The quickest previews are the least accurate, the slowest previews are the most accurate. This preview is not as quick as a glance over the storyboard, and not yet any more accurate, because your app is still too simple for that. 

Apple's gives you a good or fast experience in Xcode, never both at once

<= Preview Your Interface


Let Apple misuse technical words


For a piece of Swift code to "adopt a protocol" is a specific technical thing you'll soon learn. Apple's first mention of the word "adopt" has nothing to do with that specific thing. It's a strangely unnatural word choice, no kind of plain language.

Apple has forgotten the value of careful word choices

<= Adopt Auto Layout



Let Xcode lose your new constraints


Xcode really will casually discard all your input inside its Add New Constraints popup.


You have to read and understand the tutorial of how to work that popup, and only then go work that popup from start to finish. As often as you stop in the middle to switch focus back to the tutorial, you have to start over.


Apple has forgotten the value of stepwise improvement.


<= Adopt Auto Layout




Learn debugging later


Apple neglects to mention that the new constraints appear in the Outline View. Make time to find them there. Otherwise, you won't have any way to review your work. You won't know how often you wrongly accidentally create too many constraints, too few constraints, or some constraints with the wrong values.

Apple talks as if you're likely to have departed from their instructions far enough to make use of Update Frames, Resolve Auto Layout Issues, Reset to Suggested Constraints, and Choose Clear Constraints. Tell us if you do, I never have.

Apple has forgotten the value of immediate visual feedback

<= Debugging Auto layout



Download and compare


Apple does end this chapter, its chapter 1 of 10, with a download named "01_BuildABasicUI".

You can download that work and compare that work with yours. It will have the same "FoodTracker" name as your work, which can be confusing, so you might should make a point of forgetting about it, by choosing Xcode > File > Open Recent > Clear Menu.

If you know Terminal Diff, then you can get a lot of learning out of telling your MacBook to highlight every small difference between their work and yours.
cd ~/Downloads/01_BuildABasicUIcd ~/Documents/xCode-Projects/FoodTrackerdiff -burp ~/Downloads/01_BuildABasicUI .
The space-dot " ." on the end of those instructions is crucial, and easy to overlook.

Apple forgets to strongly recommend you compare your progress with theirs

<= Wrapping Up


Back up your progress



If you know Git, you should make the Source Control > Commit choice now. Your Commit Message could be "Build a Basic UI". This choice captures your progress now, so you don't lose it, so you can always come back to it. This choice moves the baseline, so you that Source Control > Discard Changes brings you back here, after now.

If you don't know Git, you've still got to find some way to capture progress. Odds on you can quit Xcode and copy the project folder to back it up. I haven't tried that, but it looks like it works.

Mostly, if you're coding in 2017 without knowing Git, now is a good time to catch up. Xcode Source Control might be intuitive enough to pick up quickly. Tell us how it goes? Tell us if Xcode loses some of your work as you learn?

Apple leaves your Discard Changes defined to slap you all the way back to your beginning


<= Wrapping Up




Back | Forward | Source: Apple Developer >  Build a Basic UI

No comments: