XCode - learnclang/1-helloworld GitHub Wiki

Download XCode from the App Store. I think it's around 5 gigs and on a fast connection will probably take about an hour to download and install. The current version is 6.1.1. This ships with the OSX 10.10 SDK for OS X and the iOS8.1 SDK. This may not always be what you need for your specific needs, particularly with application plug-in development.

For example, Maya 2014 works with XCode 4.3.3 with (I believe) the 10.8 SDK and Maya 2015 is only confirmed to work with XCode 5.0.2 which uses the 10.8 SDK(and maybe 10.9). I, however, use Maya 2015 with XCode 6.1.1 and the 10.10 and I have(yet) to run into problems, although I'm sure I will. You can view the tutorial I wrote for Maya Plugins with XCode here.

Apple makes it hard to get older versions of XCode or the SDK separately(I'm not even sure if you can get the SDK without XCode). If you have any internet savvy, you'll be able to find and download an older version.

However, for our purposes here, this is of no consequence. We'll be building the simple Rock Paper Scissors Tutorial from scratch within XCode. For the purposes of this tutorial, we'll be building it as a Command Line Tool and not as a graphic interface. I will append to this at a later time, when it is more imperative and I have more time. If you're following along with the Hello, World program, you can simply swap out the code with the helloworld.c code. The images will show the Rock Paper Scissors code, to which you can refer back here whenever you get to that lesson. Also, if you're still in the Hello World phase, you do not need to do the Terminal stuff in the final step, you can merely stop after Running CMD+R.

After downloading, installing, and agreeing to the Terms & Conditions stuff, boot up XCode. You will not see a splash screen, as XCode does not have a default open window or splash screen. Instead, go to the menu bar, go to File > New > Project. xcodetutorial_startwindow

Select OS X > Application > Command Line Tool.

xcodetutorial_productinput

This will bring up a window to name your "product" - which is your project, and I'll be choosing the title of "rps" The Organization Name and Identifier are not important right now, but the XCode guidelines list somewhere to do the inverse of what your website is, therefore my domain is alexwidener.com and my Identifier will be com.alexwidener -> But always make it a com, don't make a net or any other domain name.

Lastly, I'll be choosing C, but the options are Swift, Objective C, C++ and C.

The next window will ask where you want to place it. I create scratch projects for most of my C stuff, as it's usually all just learning stuff and testing stuff out. I also uncheck the Source Control button because I don't need it for these purposes.

The next screen you'll get is terrifying at first. Even though it's definitely improved over the last few versions, it's still just a convoluted mess of stuff. However, you don't need to pay attention to most of it starting out, especially for these purposes. However, if you do run into problems with building that is not related to code errors, you'll need to come back here and start checking stuff.

xcodetutorial_buildsettings

If you look to the left sidebar, in the upper left corner, you'll see a folder icon outlined in blue, this is your Project Navigator, how you keep track of all your files. Below that is the Project itself, with the blue page icon, and everything subsequently underneath that is what makes up the project. The rps folder is where my code is, and the products is where my build ends up.

Back up to the blue folder icon, the Project Navigator, there are a few more icons and you need to get used to using them. In order from left to right, they are: Project Navigator Symbol Navigator Find Navigator(finding specific code within the project) Issue Navigator(warnings and errors) Test Navigator Debug Navigator Breakpoint Navigator Report Navigator.

In order to get back to the Build Settings, you need to be in the Project Navigator, and need to select the Project(the top level).

To the direct right of the Left Sidebar, you'll see Project and Targets. If you don't see it(it's in my image), press the blue button directly above where it is in my image(on the menu bar for the project).

After that, click Targets. You'll then see(in the image above) that there are three sections that we won't go over right now: Build Settings, Build Phases, Build Rules. Just be aware of them for when errors come up. For now, as long as you're using the Base SDK set to Latest OS X(10.10 for me), you'll be fine. Take 10 minutes and look through all of this stuff to get familiarized with it, but don't change anything.

Now click Project(above Targets) - this has Info and Build Settings, much of the same stuff, but more of the preliminary stuff, before you start compiling and building for specific builds.

I'm not going to go over the stuff on the right side at the point, as we do not need it. Play around with it and familiarize yourself, but it's not imperative currently.

Go back to the Project Navigator, open the rps folder(or whatever you named it) and click main.c

xcodetutorial_mainc

This is a file that's generated automatically when you start a new project. It's Hello World with automatic boilerplate. I'm going to replace it with the rock paper scissors code.

xcodetutorial_rps

As you can see in the image, there are two warnings in the left sidebar(of the code, not where the Project Navigator is). Clicking these will show you what the warning is, which is just a notification that there is a conversion problem between types. However, this is fine for these purposes.

You can also use the Issue Navigator(again, left sidebar, the triangle exclamation mark icon) to see them in a list format. Build Errors will also show here with a red stop sign icon.

You can go ahead and build now, in a few different ways, each with a different result. I hit CMD + R, usually just testing stuff out, however with the way this RPS program is built, it's not really useful - but it is exactly what we need for the Hello, World program. CMD + R will build and run the code, but we can't do that with this code, because this is a Command Line Tool and needs to be passed in two arguments. Using CMD + R will bring up a console at the bottom of the screen, as shown below.

If you're following with the Hello, World code you can stop here. The succeeding Terminal step is not useful to the Hello, World.

xcodetutorial_cmdr

As you see in the bottom panel on the right side, the program just ends because it wasn't passed in the arguments.

CMD + B will build the code but not run it. After that we can navigate with the OS Terminal to the directory.

xcodetutorial_terminal

And that's all!

Take time to learn about where everything is in XCode, take a good hour just navigating in the IDE and getting used to stuff. Also, if you want to compile from the command line, I wrote another tutorial on the sidebar to the right that tells you how to compile using the Xcode compiler from Terminal(GCC). I tend to prefer doing that, but it's a personal preference.

Once we start getting into UI-type stuff, I'll try and remember to come back and update this, as it's a whole other ballpark.