How do I run my program?

When the contents of your main.c file match what you see above, it’s time to run your program and see what it does. This is a two-step process. Xcode builds your program and then runs it. When building your program, Xcode prepares your code to run. This includes checking for syntax and other kinds of errors.

Look again at the lefthand area of the Xcode window. This area is called the navigator area. At the top of the navigator area is a series of buttons. You are currently viewing the project navigator, which shows you the files in your project. The project navigator’s icon is How do I run my program?.

Now find and click the How do I run my program? button to reveal the log navigator. The log is Xcode’s way of communicating with you when it is building and running your program.

You can also use the log for your own purposes. For instance, the line in your code that reads

 ​ ​ ​ ​p​r​i​n​t​f​(​"​I​t​ ​w​a​s​ ​t​h​e​ ​b​e​s​t​ ​o​f​ ​t​i​m​e​s​.​​n​"​)​;​

is an instruction to display the words It was the best of times. in the log.

Since you haven’t built and run your program yet, there isn’t anything in the log navigator. Let’s fix that. In the upper lefthand corner of the project window, find the button that looks suspiciously like the Play button in iTunes or on a DVD player. If you leave your cursor over that button, you’ll see a tool tip that says Build and then run the current scheme. That is Xcode-speak for Press this button, and I will build and run your program.

If all goes well, you’ll be rewarded with the following:

How do I run my program?

If not, you’ll get this:

How do I run my program?

What do you do then? Carefully compare your code with the code in the book. Look for typos and missing semicolons. Xcode will highlight the lines it thinks are problematic. After you find the problem, click the Run button again. Repeat until you have a successful build.

(Don’t get disheartened when you have failed builds with this code or with any code you write in the future. Making and fixing mistakes helps you understand what you’re doing. In fact, it’s actually better than lucking out and getting it right the first time.)

Once your build has succeeded, find the item at the top of the log navigator labeled Debug AGoodStart. Click this item to display the log from the most recent run of your program.

The log can be quite verbose. The important part is the Dickens quote at the end. That’s your code being executed!

G​N​U​ ​g​d​b​ ​6​.​3​.​5​0​-​2​0​0​5​0​8​1​5​ ​(​A​p​p​l​e​ ​v​e​r​s​i​o​n​ ​g​d​b​-​1​7​0​5​)​ ​(​T​u​e​ ​J​u​l​ ​ ​5​ ​0​7​:​3​6​:​4​5​ ​U​T​C​ ​2​0​1​1​)​
C​o​p​y​r​i​g​h​t​ ​2​0​0​4​ ​F​r​e​e​ ​S​o​f​t​w​a​r​e​ ​F​o​u​n​d​a​t​i​o​n​,​ ​I​n​c​.​
G​D​B​ ​i​s​ ​f​r​e​e​ ​s​o​f​t​w​a​r​e​,​ ​c​o​v​e​r​e​d​ ​b​y​ ​t​h​e​ ​G​N​U​ ​G​e​n​e​r​a​l​ ​P​u​b​l​i​c​ ​L​i​c​e​n​s​e​,​ ​a​n​d​ ​y​o​u​ ​a​r​e​
w​e​l​c​o​m​e​ ​t​o​ ​c​h​a​n​g​e​ ​i​t​ ​a​n​d​/​o​r​ ​d​i​s​t​r​i​b​u​t​e​ ​c​o​p​i​e​s​ ​o​f​ ​i​t​ ​u​n​d​e​r​ ​c​e​r​t​a​i​n​ ​c​o​n​d​i​t​i​o​n​s​.​
T​y​p​e​ ​"​s​h​o​w​ ​c​o​p​y​i​n​g​"​ ​t​o​ ​s​e​e​ ​t​h​e​ ​c​o​n​d​i​t​i​o​n​s​.​
T​h​e​r​e​ ​i​s​ ​a​b​s​o​l​u​t​e​l​y​ ​n​o​ ​w​a​r​r​a​n​t​y​ ​f​o​r​ ​G​D​B​.​ ​ ​T​y​p​e​ ​"​s​h​o​w​ ​w​a​r​r​a​n​t​y​"​ ​f​o​r​ ​d​e​t​a​i​l​s​.​
T​h​i​s​ ​G​D​B​ ​w​a​s​ ​c​o​n​f​i​g​u​r​e​d​ ​a​s​ ​"​x​8​6​_​6​4​-​a​p​p​l​e​-​d​a​r​w​i​n​"​.​t​t​y​ ​/​d​e​v​/​t​t​y​s​0​0​1​
[​S​w​i​t​c​h​i​n​g​ ​t​o​ ​p​r​o​c​e​s​s​ ​2​7​2​3​ ​t​h​r​e​a​d​ ​0​x​0​]​
I​t​ ​w​a​s​ ​t​h​e​ ​b​e​s​t​ ​o​f​ ​t​i​m​e​s​.​
I​t​ ​w​a​s​ ​t​h​e​ ​w​o​r​s​t​ ​o​f​ ​t​i​m​e​s​.​

(As I’m writing this, Apple is working on a new debugger called LLDB. Eventually it will replace GDB, the current debugger. If you aren’t seeing all the GDB information, it means that LLDB is now Xcode’s standard debugger. The future must be a terrific place; I envy you.)

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset