Book Image

Mac Application Development by Example: Beginner's Guide

By : Robert Wiebe
Book Image

Mac Application Development by Example: Beginner's Guide

By: Robert Wiebe

Overview of this book

It's never been more important to have the ability to develop an App for Mac OS X. Whether it's a System Preference, a business app that accesses information in the Cloud, or an application that uses multi-touch or uses a camera, you will have a solid foundation in app development to get the job done.Mac Application Development by Example takes you through all the aspects of using the Xcode development tool to produce complete working apps that cover a broad range of topics. This comprehensive book on developing applications covers everything a beginner needs to know and demonstrates the concepts using examples that take advantage of some of the most interesting hardware and software features available.You will discover the fundamental aspects of OS X development while investigating innovative platform features to create a final product which take advantage of the unique aspects of OS X.Learn how to use Xcode tools to create and share Mac OS X apps. Explore numerous OS X features including iCloud, multi-touch trackpad, and the iSight camera.This book provides you with an illustrated and annotated guide to bring your idea to life using fundamental concepts that work on Mac.
Table of Contents (17 chapters)
Mac Application Development by Example Beginner's Guide
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Time for action - creating the SimpleCalc Xcode project


Now that we have installed Xcode, we can start using it to write our own Mac OS X App. Let's get started:

  1. To create a new Xcode project, launch the Xcode App and click the button titled Create a new Xcode project on the Welcome to Xcode window as shown in the following screenshot:

  2. When Xcode asks us to select a template, select Application under Mac OS X and Cocoa Application as the template. Then, click on the Next button.

  3. When we click the Next button, Xcode will ask us to select options for our new project. The options that we need to select are as follows:

    Option

    Value

    Description

    Product Name

    SimpleCalc

    The product name will be the name of your App program file that shows up in the Mac OS X Finder.

    Company Identifier

    com.yourdomain

    com.yourdomain The company identifier needs to be unique and typically uses the reverse domain notation. It can be anything but you should use a company identifier that will not conflict with an existing company. If you don't have an Internet domain name you can acquire one new or you can use com.yourlastname.first name.

    Class Prefix

    Your Initials

    (For consistency, throughout this book we will use BTS but when you develop your own code you should use your own initials)

    The class prefix is used to make sure any program classes that you create do not have the same name as any program classes that someone else may create.

  4. Finally, there are some checkboxes at the bottom of the options screen. The only one that needs to be checked is the option titled Use Automatic Reference Counting. This setting permits Xcode to automatically manage the memory that our program uses and helps keep programing simple because we do not need to think about destroying objects that our program creates. This checkbox, along with the rest of our settings, is shown in the following screenshot:

  5. Click on the Next button and Xcode will ask us where we want to save the new project that we are creating. While we can save projects anywhere that we like, a good place may be a new folder called projects in our Documents folder. Whatever we decide, when we have navigated to that folder, we need to click on the Create button as shown in the following screenshot:

    Tip

    Xcode automatically creates project subfolders

    We do not need to create a subfolder in the projects folder because Xcode will do that automatically using our product name. If we look for our project folder in the Finder, after Xcode has created it, we will find it in projects/SimpleCalc.

What just happened?

When we clicked on the Create button, Xcode created the new project from the template that we chose and displayed its main interface window.

Tip

Don't Panic

The main Xcode window can be quite overwhelming. The following screenshot shows the entire interface simply to give us an idea of its scope. We don't need to understand all of the sections or be intimidated by Xcode's main window. As we get deeper into programming, we will learn more about each part of the window.

As we progress in our App development and become more familiar with Xcode, we will become comfortable with the contents of this interface. Xcode's interface is very similar to iTunes. It contains the following:

  • A control area along the top where we can build and run ("play") or stop our App

  • A navigation area on the left where we can select different components of our project to inspect

  • An editing area in the center where we can modify different components that were selected in the navigation area

  • A utilities area on the right where we can inspect and change attributes of selected items

It is a good idea to take some time now to become familiar with the meaning of each of the little icons for the navigator section of the Xcode view, which appear across the top of the navigation area on the left-hand side of the window. The following table gives descriptions of these icons:

Icon

Description

Shows the project navigator, which lists all of the files in this project

Shows the symbol navigator, which lists all of the symbols (method names, property names, and so on) in this project

Shows the search navigator, which lists all of the search results for anything that we want to search for in the project

Shows the issue navigator, which lists all of the issues (typically error or warning)

Shows the debug navigator, which lists all of the App threads and symbols if a debug session is active

Shows the breakpoint navigator, which lists all of the places we want the App to stop at so that we can inspect its state during an active debug session

Shows the log navigator, which lists a log of the different activities that we have performed

Xcode will sometimes change the selected navigator based on actions that we perform or events that occur. It is useful to know that we can always switch back to the navigator that we want to see by clicking on the appropriate icon.