Making Your iOS Apps Fit for Consumption - dummies

Making Your iOS Apps Fit for Consumption

By Rajiv Ramnath

Part of Beginning iOS Programming For Dummies Cheat Sheet

iOS program performance is more than background processes. A few simple tricks can save time and increase performance. For the straight story, check out these hints.

Quickly finding and opening relevant files in Xcode

Use the Open Quickly command to find and open a file at a specific line, using its filename, type, or a symbol in the file (like a variable or function name), as follows:

  1. Choose File→ Open Quickly.

  2. In the search field, type characters in the name of the file or symbol you want to view.

  3. Type a dot followed by one or more characters of the filename extension.

  4. To have the file open at a specific line, type a colon followed by the line number.

  5. Choose a file from the results list.

This dialog also lets you decide where to place a file in Xcode. Just press and hold CMD+OPT+SHIFT while double-clicking the file.

Configuring behaviors

You can configure how Xcode responds to common events by setting its behavior using the Xcode→Preferences→Behavior settings page to set behavior preferences.

For example, you can have a certain set of tabs appear when Xcode runs your app. Or, if a build fails, you can make Xcode save a snapshot and open the debug area in your workspace window.

Creating a .gitignore file

Xcode can easily connect with git, a popular source code management system. If used without any configuration, git will try to archive everything in a project, even files with compiled object code, executables, and temporary files used by Xcode.

To fix this issue, you need to create configure git appropriately. To do this, navigate to the project folder and create a .gitignore file with the following content:

OS X Finder
# Xcode per-user config
# Build products
# Automatic backup files

Popping up an Alert view

Your app often needs to pop up an alert to let the user know something happened and that she has a choice of actions. Here is a quick checklist for how to set up an alert.

  1. Implement the clickedButtonAtIndex method in the class that will cause the alert to pop up.

    The following example code shows you how:

        - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
            if (buttonIndex == 0){
                [self playNewGame];
            } else if (buttonIndex == 1) {
  2. Create, initialize, and show the alert.

    The following snippet of code shows you how:

    UIAlertView *alert = [[UIAlertView alloc] init];
    [alert setTitle:@"Game Over!"];
    [alert setMessage:@"Play Another Game?"];
    [alert addButtonWithTitle:@"Yes"];
    [alert addButtonWithTitle:@"No"];
    [alert setDelegate:self];
    [alert show];