Compile and run your iOS apps using Apple’s latest compiler. Then test your app on iOS Simulator and also, preferably, on a device.
Creating an iOS App can be categorized under the following tasks:
Planning
Prototyping
Designing
Implementing and Testing
Delivering
During the implementation of an app, you will constantly need to run your app on a simulator or on various devices to make sure it is consistent, adheres to the design guidelines that you or your teammates created for this project, and most importantly, is stable enough for the App Store.
Note
Crashes provide one of the major reasons for app rejections in the Apple App Store. Apps that are not stable and crash often are not good enough for consumers and Apple is very likely to reject them. So always make sure that you thoroughly test your apps on iOS Simulator and on devices.
When we write our code, as we will learn very soon, we need to make sure that what we are writing is correct. The process by which Xcode changes our code into executable instructions is called compilation. The compiler does the compilation. In Xcode, we use various build commands to compile our apps:
- Build for Running
Use this when you want to debug your applications on the simulator or on a device. Debugging is the process by which you can find mistakes in your code.
- Build for Testing
Use this build setting to run unit-tests that you’ve written for your apps. Unit tests, in short, are a set of instructions that you provide to Xcode. Xcode will run these instructions before it makes the final build. These instructions have one purpose only: to make sure that each part of the app you’ve written is in full working order.
- Build for Profiling
If you want to test the performance of your app, use this setting. Profiling is the process by which you can find bottlenecks, memory leaks, and other quality-related issues not covered by unit testing.
- Build for Archiving
When you are sure your app is production quality or simply want to distribute it to testers, use this setting.
To compile your apps, in Xcode, simply select the Product menu item, choose Build For, and then choose whichever build setting you believe is relevant to the task you want to accomplish.
What do you think happens if you have an error in your code? In Recipe 1.1 we created a simple Page-Based Application, so let’s go back to that app. Now open the RootViewController.m file in your project and look for this code:
- (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; }
Change this code to the following:
- (void)viewWillAppear:(BOOL)animated { [super nonExistantMethod]; [super viewWillAppear:animated]; }
If you now try to use Product menu, Build For, and then Build For Running, you will get the following error from Xcode:
error: Automatic Reference Counting Issue: Receiver type 'UIViewController' for instance message does not declare a method with selector 'nonExistantMethod'
This is what the compiler is telling you: the code that you’ve
written cannot be compiled and translated to proper instructions to
the CPU. In this particular case, this is because the compiler doesn’t
understand what nonExistantMethod
actually
is. This illustrates a good compiler that warns of and sometimes stops
you from making mistakes that make your apps unstable.
Get iOS 5 Programming Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.