Monster iOS

Monster iOS: A New Beginning – Chapter 1 Section 3

[boilerplate buy-buttons]
 

Interested in Monster iOS: A New Beginning but want to take a look first? Great! We’ve got the introduction and first chapter available for you to look at.

Introduction
Chapter 1 – The Bit About Bytes
Section 1 – Dave Awakes
Section 2 – Monsters’ First Project
Section 3 – Xcode for Monsters


Xcode for Monsters

“Whaf? More sfuff fo learn?”

Dave wondered if Vincent was going to burst into tears. He sounded as if he was ready to do so. “There’s a lot more to learn if you want to be iOS developers,” he said. “This is just the beginning. You haven’t even gotten to the programming part yet …”

“When will we gef fo fhaf?” asked Vincent, leaning forward and looking eager.

“Slow down, cowboy. That won’t be for a bit. You have to first learn about how to get around in Xcode.”

“Awww!” said Vincent, while Wendy gave him another one of her stares.

“The sooner we get started, the sooner you’ll get to the coding,” said Dave, eager to get this done as soon as he could. His stomach was growling louder than Wendy at this point and he was hoping that the monsters would want to break for breakfast soon … as long as he wasn’t the breakfast.

“OK, what do we need to know?” asked Wendy.

“Again, you’ll notice that this window is basically composed of sections and panes.”

“Pains? Whaf does pain have fo do wifh if?” asked Vincent, looking interested.

“I said panes, not pain,” said Dave hastily. “The window is basically four panels as you see it now. There’s the tool bar at the top, the navigation pane on the left, the utilities pane on the right, and the editing pane in the center.”

“Ah, fhaf makes more sense,” said Vincent, looking less enthusiastic.

c1s3-1

 

“And then each pane is again sub-divided as in the case of the utilities pane?” asked Zane.

“Yes, exactly!” said Dave, glad to see that somebody was paying attention. “Once you learn what each section does and how to use it to create an app, you’re halfway there to being an app developer …. OK, maybe only a quarter way, or more like one eighth …”

“We get the point! Let’s move on,” growled Wendy.

“Umm … yes. So the first thing you should notice is the toolbar. It’s again basically three zones. The left portion has actions which affect your project, the center shows you the status of your project, and the right portion allows you to control the appearance and functionality of Xcode.”

c1s3-2

“So whaf does fhaf buffon do?” asked Vincent, pointing at the screen.

“I was getting to that,” said Dave, trying not to snap. “The first button builds and runs your current application …”

“Build? Didn’t we just build the application by selecting the template and so on?” asked Wendy.

“The word build here means something slightly different. Here, when I say build, I mean that the compiler compiles the project and creates an executable file.” Dave could see that Vincent was getting ready for another question and rather than trying decipher his lisped sentences, Dave decided to get to what he knew was coming. “Yes, Vincent, I think you’re about to ask me about compiling and what an executable is?”

Vincent nodded vigorously.

“You know that you write programs in human … and monster”, he added hastily “understandable form, right?”

The others nodded.

“The computer can’t understand that code the way you write it. You write the code in something like English, but the computer only understands bits and bytes.”

“Fhe compufer can bife?” asked Vincent, perking up.

“No Vincent, not bite. I said byte. B – Y – T – E. That’s one of the units of measurement used in computing when you talk about data storage on a computer. A computer works in binary, which before you ask, is a number system which has only two digits – one and zero. So everything that the computer does is basically in ones and zeros.”

“Huh. So how does if counf fo 10 fhen?”

“OK, I can see that this is going to get complicated,” said Dave, wondering if he was getting in too deep. “Binary numbers[6] work slightly differently than decimal numbers. The number 10 in binary is represented using just ones and zeros, but in that case the number 10 would be 1010.”

“Why?”

“Because in binary each position is a power of two and …” Dave paused and considered. “OK, I can see that this is getting a bit complicated. You don’t need to really know how binary works most of the time. But if you’re interested, look it up since there are some good explanations online. The important thing is that a computer works in bits and bytes and all instructions on the computer are represented in what is known as machine code. The compiler is a part of Xcode which will take the program you write in English and converts it into binary machine code. The final compiled code is known as an executable because you can … umm .. Execute it, makes sense?”

The others didn’t look as if they quite got it. Dave waved his hand and said, “OK, forget all that. Just think of the compiler as something which checks your code for problems and then creates the final application based on the code you write. Clear?”

The three monsters nodded, some vigorously, the others a lot more slowly as if they were still trying to digest all this information.

“You said the compiler looks for problems. What kind of problems?” asked Wendy.

“I’ll get to that soon. But let’s get through the Xcode UI first,” replied Dave. “OK, so what the first button, which is called the Build and Run button, or simply the Run button, does is to create a running version of your application …”

“But what if the compiler finds any problems when it checks your code?”

“Excellent question,” Dave smiled. “That’s when you do some debugging to find the problem.”

“Is that like picking fleas off your fur?” Wendy again.

“No, not quite. But then again, I guess it is something like that since you have to hunt around for the bugs and when you find them, you squash them.”

That got a huge response from all three of his students. Dave was beginning to see a pattern here. Anything to do with pain, suffering, and killing seemed to be what appealed to his students. As long as the pain and suffering wasn’t his own, Dave was OK with that. He made a mental note to add more gore to his lessons.

“Can we fry running fhe sample applicafion?” asked Vincent, looking hopeful.

“Sure, why not? Why don’t you do the honors?” Dave asked, gesturing to Vincent.

Vincent gingerly approached the computer, moved the cursor over to the Run button and clicked it. A dialog popped up and Vincent stared at it.

c1s3-3

“What do we do now?” asked Zane.

“Oh that’s just a message you get the very first time you run Xcode on a computer, not to worry. Just tap Enable and you’re set,” said Dave, tapping the Enable button. Which resulted in another dialog.

“Don’t worry about this either. It’s just asking for the password. Good thing you have it in big letters over there on that whiteboard. I don’t have to worry about remembering it at all,” said Dave, internally shaking his head at how bad security practices wasn’t purely a human thing. And that brought up yet another dialog.

c1s3-4

“Are we ever going fo gef fhis app running?” asked Vincent plaintively.

“Ah, but this is a good one. This is what you’d call a teachable moment,” said Dave, grinning. His grin froze though as he saw Wendy beginning to snarl. But it turned out that she just wanted to say something.

“So teach us,” was all she said.

“Well, let me first get rid of this message,” he said while tapping the OK button. “Did you see what the message said?”

“Something about provisioned devices. What does food have to do with iPhones? Does it mean that the iPhone battery needs charging?” asked Zane, looking puzzled.

“No, this provisioning is different. As I mentioned earlier, you need a paid developer account if you want to test on devices. And the process of setting up a device for testing via Xcode is called provisioning. But we currently don’t have a device attached to the computer. That’s why Xcode showed that error message.”

“So do we have to bring the iPhone over here?” asked Zane, not looking pleased at the prospect of heavy labour.

“That’s one way to do it,” agreed Dave. “But you could also test your application on the simulator.”

“What’s a simulator?” asked Wendy.

“Like the name indicates, it’s a program which simulates an iPhone … or another device like an iPad.”

“How does it work?” asked Zane.

“That’s not really my area,” hedged Dave. “But it’s a program which behaves like an iOS device where you can load your program and test it, instead of having to run the program always on device. This way, even people who don’t have a paid Apple developer account can test their code easily.”

“Ah, fhaf make sense,” nodded Vincent. “How do we run on fhe simulafor?”

“See this section on the toolbar which says ‘iOS Device’?” asked Dave pointing to the left side of the toolbar again. The others nodded. “That is where you select the destination for your app. Currently, it is set to run on an iOS device but since one isn’t present, you got that error. But if you tap on the iOS Device item to drop-down the list of available choices like this, you can then select a simulator from the list instead.”

c1s3-5

“Ah,” said Zane. “So that’s where that was hiding! What does the other part do?”

“Which part?”

“The part which says Sampl…

“You realized that was a drop-down list too? Very good!” said Dave, pleased. “That part lets you select the project target.”

“What’s a project target?” asked Wendy.

“Sometimes, an Xcode project can create multiple versions of the same app. For example, let’s say that you want to create a free version of your app as well as a paid version. Both versions have the same functionality but the free version will show ads to generate revenue. Since the functionality is the same in both apps, there is no point in having the two apps as two separate Xcode projects, is there?”

“Why nof?”

“Well, if you have two separate projects, then when you change something in one project, you have to remember to make the same change in the other one too. So, you always end up doing twice the work even though the functionality is almost the same. With targets, you can have the same code but build two different versions of the app …”

“How can the code be the same if one shows ads and the other doesn’t?” asked Wendy.

“OK, the code isn’t exactly the same. It’s mostly the same. Basically, you can detect which version of the app you are on and decide whether to display the ads or not …”

“And how do you do fhaf?”

“That’s again a fairly complicated subject …”

“Fhaf’s whaf you always say!” Vincent sounded accusing.

“Hey, you guys haven’t done any development yet. So I can’t explain a lot of this to you in a way that makes sense. We will get back to supporting multiple targets once you know how to do at least one app, OK?”

“Alrighf …”

“Anyway, as I was saying, you can use the target drop-down to select the target, and from there, you can select the destination, too, if you like,” said Dave, tapping on the screen.

c1s3-6

“Cool! So if I had several targets, I can select the target and the destination at the same time?” asked Zane.

“Yep.”

“Why does it show two iPhones and iPads under simulator?” asked Wendy.

“That’s for you to be able to test on all the different iOS device models and the differences in screens between retina and non-retina…”

“Whaf’s a refina screen?”

“Vincent, haven’t you been paying attention to Apple news?” replied Zane. “The retina display is Apple’s term for high resolution screens where the eye can’t see individual screen pixels. On the older Apple displays, you could still see the pixels. They’ve had retina displays on iPhones since iPhone 4.”

“Yep, that’s right,” agreed Dave, “So the first iPhone in the list is a pre-iPhone 5 device with a retina display and the other is an iPhone 5 since it has a taller, 4-inch screen. The first iPad is a non-retina device and the second one is a retina iPad.”

“And it doesn’t matter which one we test on?” Wendy looked as if she still wasn’t sure what all these devices were for.

“I’d suggest you test on a retina device for certain since these days most Apple devices have retina screens. But it’s good practice to test on all of them at least once so that you know your app works across all devices correctly. But one thing to always keep in mind if you’re going to submit to the App Store, always test on device and not just rely on simulator testing.”

“Why not?” asked Zane. “If the simulator duplicates device functionality, we should be able to do all our testing on simulator, right?”

“Nope. Since that assumption is going to land you in trouble sooner or later. A simulator does not replicate conditions or functionality on a device exactly. For instance, since the simulator doesn’t have a camera, you can’t test any image capture or video functionality …”

“Can’t you use the camera on the Mac?” asked Wendy.

“That’s what I’d like to see working too,” said Dave, smiling broadly. “But for the time being, the simulator doesn’t support that and so you have to test certain things on an actual device.”

“What else?” asked Zane.

“Do you mean what other stuff do you have to test on an actual device? Well, any accelerometer stuff, compass, GPS coordinates, sometimes even music or video playback is a bit iffy on the simulator ….”

“No, I meant what are the other reasons for not relying on simulator testing only?” clarified Zane.

“The other major reason is that the simulator has more memory and disk space than an actual device. Basically, a simulator can use all the memory and disk space available to your Mac. So you won’t catch resource issues as easily, if at all, on a simulator.”

“OK, that makes sense,” nodded Zane.

“Can we run somefhing already?” asked Vincent plaintively.

“Sure, sure,” said Dave hastily. He selected one of the simulators and tapped the Run button. “Pay attention to the center section of the toolbar. Notice how it says ‘Building application’? It’ll show you status information there as Xcode carries out various actions. And when Xcode’s done, you get this!”

c1s3-7

“Wha …? Buf fhaf’s jusf an empfy window!” wailed Vincent.

“As I said originally, it’s a very simple app,” said Dave smugly. “We’ll add some functionality to it soon and make it do something a bit more exciting but we should finish this bit about the toolbar first.”

“Oh alrighf!” said Vincent, looking like a petulant child denied dessert.

“There’s only just a bit more to the toolbar, really,” said Dave, feeling a little sorry for the vampire. After all, he did remember the first time he’d worked on an iOS app and how eager he’d been to “get something working” …

“As you would have noticed,” he continued, “the button next to the Run button becomes enabled when you’re running an app. That’s because that’s the Stop button …”

“And it stops the running application?” asked Zane.

“Exactly. And that concludes all the default buttons on the left of the toolbar!”

“What about the buttons on the other side?” asked Wendy.

“Those mostly control the various view options for Xcode…”

“Such as?” Dave was really beginning to hate Zane’s interruptions. Plus his stomach was growling again, even louder than before.

“The toolbar buttons are in two sets of three buttons each, as you’ll notice. The first set controls the various editor views.”

“You mean you can have more than one editor view?” asked Wendy.

“Yes, you can have the normal text editor, which you haven’t seen yet …”

“Can we see if?”

“Sure, just select any of your source code files — they are the ones listed on the left in the navigator pane, by the way — and you’ll see the standard editor for Xcode, like this.”

c1s3-8

“Soooo colorful!” said Vincent, looking at the screen rapturously.

“Yes, the code editor displays various Objective-C syntax elements in different colors. I’ll explain that further when we get to the editor part. But for the time being, you’ll notice that the first button in the toolbar’s editor section … ”

“How do you know which is the editor section on the toolbar?” interrupted Wendy.

“As you continue to use Xcode, this will become pretty familiar to you but if you’re not sure about something when you start out, you can always enable captions for the toolbar icons.”

“How do we do fhat?”

“Simply right-click, or Control+click since that’s the same thing on a Mac, on the toolbar and you’ll get a menu which allows you to customize the toolbar. Like this.”

c1s3-9

“And you select the ‘Icon and Text’ option?” asked Wendy, looking triumphantly at Zane.

“Exactly! When you do that, all your buttons and sections on the toolbar get titles, like this.”

c1s3-10

“That’s so much better and easier to use! How come we didn’t start with that setting?” asked Zane, looking at Dave accusingly.

“Sorry, I forgot,” said Dave feeling sheepish. “I’ve gotten so used to working with Xcode that I know what the buttons are for. But if you are just beginning to learn about Xcode, this is definitely a good thing to remember. And now, you can see where the Editor section is, too!”

“Why are some of fhe buffons blue and some black?” asked Vincent.

“Great question, Vincent!” said Dave, beaming. He was almost feeling paternal towards the monsters. They actually were getting it! “The blue buttons indicate active settings or elements. So, since we’re in the standard editor mode, the first button on the editor section is blue. Watch what happens when I select the second button.”

c1s3-11

“Ooh, now fhere are fwo edifors!”

“Yes, this mode is called Assistant Editor mode because the second window shows code related to the code in the first editor window…”

“Fhey’re brofhers or sisfers?”

“No, not related like that! In this case, related means code which has some connection to the code in the first window. But since I haven’t gotten to what the source files mean …”

“You’ll explain it better later!” chorused the three monsters.

Dave smiled. “Right.”

“But it’s really hard to read all the text squished up like that,” said Wendy. “Is there something that you can do?”

“Yes. And that brings us to our last set of toolbar buttons. The view buttons. Notice how the first and last view buttons are blue? Can you guess what they do?”

“I know,” said Zane, “They control the left and right panels!”

“Very good! Yes, that’s exactly what they do. See what happens when I click on both the first and last buttons to turn off the panels.”

c1s3-12

“Much better!” said Wendy. “So does the middle button in the view section turn on a pane at the bottom of the Xcode window?”

“Yep! It shows the debug area but since we haven’t covered debugging yet …” Dave paused expectantly.

“You’ll explain it later!” said all three monsters together, making Dave smile again.

“Yep. And I think that about covers the toolbar …”

“But the code is still a bit squished together,” said Wendy. “Wouldn’t it be easier to read if the editors were one above the other instead of side-by-side?”

“Actually, you can do that, yes.”

“Which toolbar button does that?” asked Zane.

“For that you have to go to the Xcode menu,” said Dave. “You see the View item on the menu?” The monsters all nodded.

“That’s what controls the various options for how the Xcode window looks. And if you select the view option, you’ll see a sub-menu for all these different view control options, like this.”

c1s3-13

“And you select ‘Assistant Editor’?” asked Wendy.

Dave beamed like the transporter room of the USS Enterprise. “Absolutely! And under that menu, you’ll see the following options.”

c1s3-14

“Ooh, ooh, I know! Assisfanf Edifors on Boffom!”

“Yes! Give the man a cigar!”

Vincent looked confused. “I don’f wanf a cigar, smoking’s bad for your healfh, you know …”

“Never mind Vincent, just a figure of speech,” said Dave, shaking his head. “Having your blood drained from your body would be bad for your health too. Way worse than smoking. Somebody should tell him that!” whispered inner-Dave. Prudently, Dave decided to keep quiet lest he give Vincent any ideas.

“As Vincent said, you select Assistant Editors on Bottom, and then you have your editors stacked one on top of the other!”

c1s3-15

“That’s more like it!” said Wendy with enthusiasm. “But you forgot one thing.”

“What?” Dave asked, the crazy, gibbering-in-fear side of his mind idly wondering if they were going to say something like, “It’s feeding time!” and then jump on him all at once.

“You didn’t explain the last button in the editor section.”

Dave almost laughed out loud from relief. “Oh yeah, sorry. That one opens the Version Editor.”

“What does that do?” asked Zane.

“It lets you compare different versions of your source files if you’re using source control. But since we haven’t covered source control, that too will have to wait till later.”

His stomach growled yet again and Dave decided that it was time to throw caution to the winds and speak up. “Umm … I’ve not had any breakfast …”

Wendy growled but Dave got the impression that it wasn’t at him. She almost looked contrite as she said, “Oh, I’d totally forgotten! Here we are asking you to teach us iOS development and you’ve just woken up! How inconsiderate of us. Let’s go over to Mama Kevada’s place and get some breakfast into you!”

“What about the rest of the Xcode window sections?” Dave asked.

“We’ll get back to it after breakfast, of course!” said Zane.

Dave got up and walked out behind the monsters, wondering if this Mama Kevada had anything that humans could eat or if the monsters were playing a cruel joke on him and breakfast was going to be on him, literally.


[6] Binary Numbers: Binary numbers represent all numbers using 1s and 0s. This is the number system used internally in computers. http://en.wikipedia.org/wiki/Binary_number


Take a look at the rest of Monster iOS: A New Beginning.

Introduction
Chapter 1 – The Bit About Bytes
Section 1 – Dave Awakes
Section 2 – Monsters’ First Project
Section 3 – Xcode for Monsters

[boilerplate buy-buttons]

Leave a Reply

Your email address will not be published. Required fields are marked *