EditingThis is the process in which you create and modify Objective-C source code. Source code is the name given to the programming instructions or statements that you write to tell your computer what you want it to do. Objective-C is a particular language for writing those instructions and the resulting source code is stored in files called source files. There’s nothing special about source files, they’re just plain old text files with no extra formatting and in Objective-C they usually have a .m extension to indicate their contents. It is in the formatting information that there is a gotcha. You really need to be careful with the editor that you use to create your source code and you really really want to avoid word processors (note the different in name) such as Microsoft Word or Pages. Both of those tools (and many other word processors for that matter), add extra formatting information when they create a file and it is that formatting information that doesn’t mix well with source code. To avoid these problems, my recommendation is therefore to use Xcode as your editor. Xcode is a tool provided by Apple and is what we call an integrated development environment (IDE). This means that not only does it allow you to edit your source code (without adding any of that nasty formatting information) it also supports you through the subsequent phases of this process by allowing you to compile, link and execute your source code as well. I’ll mention this again later.
CompilingThe process of converting your source code into a language that can be understood by your computer is called compilation (the act of which is called compiling) and is performed by a tool called a compiler. First the compiler takes the output of your editing activities, source code in one or more source files, and performs a series of checks to make sure it all makes sense and doesn’t contain any mistakes. As you might expect these checks are extensive. They can be anywhere from checking that you’ve used valid Objective-C statements (the instructions we talked about in the editing phase) right through to identifying whether you have structural problems with your source code. Think of it as proof reading for your source code. If there are mistakes, you’ll need to go back and edit your code and fix them before you can move on. If there aren’t, and the compiler is happy, it will convert your source code into something that your computer can understand. The result of this conversion is something called object-code and the compiler stores this object-code in one or more object files. For each source file you supply, the compiler will generate a corresponding object file with the same file name as the source file it was created from but instead of the .m extension as we saw with source files it will give the file a .o or a .obj extension to indicate it contains object code.
LinkingOnce your program grows to any significant size, it is likely that it will consist of more than one source file. Collectively the source files that make up your application are grouped together in something called a project where the project name and your program name are usually synonymous. Splitting your source code across multiple files does introduce some overhead (in that you need to manage all the files that make up your project) but Xcode helps you with this and there are a number of benefits in doing so:
- Having multiple source files allows you to focus and work on individual sections of your application one part at a time. This can be extremely beneficial, especially if you have thousands of lines of code and can save on some serious scrolling action.
- Each individual source file can be incrementally developed to add features and functionality.
- As we saw in the previous phase, by storing your source code in individual files you can also compile each of them separately allowing you to individually eliminate typographic errors at an early stage.