www.it-ebooks.info Mac Application Development by Example Beginner's Guide A comprehensive and praccal guide, for absolute beginners, to developing your own App for Mac OS X Robert Wiebe BIRMINGHAM - MUMBAI www.it-ebooks.info Mac Application Development by Example Beginner's Guide Copyright © 2012 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmied in any form or by any means, without the prior wrien permission of the publisher, except in the case of brief quotaons embedded in crical arcles or reviews. Every eort has been made in the preparaon of this book to ensure the accuracy of the informaon presented. However, the informaon contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark informaon about all of the companies and products menoned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this informaon. First published: December 2012 Producon Reference: 1141212 Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK. ISBN 978-1-84969-382-0 www.packtpub.com Cover Image by J.Blaminsky (milak6@wp.pl) www.it-ebooks.info Credits Author Robert Wiebe Reviewers Luca Bernardi John Dumais Dominik Jaworek Jamie B. McHardy Acquision Editor James Keane Lead Technical Editor Ankita Shashi Technical Editor Sharvari Baet Project Coordinator Amey Sawant Proofreader Steve Maguire Indexer Monica Ajmera Mehta Producon Coordinator Nilesh R. Mohite Cover Work Nilesh R. Mohite www.it-ebooks.info About the Author Robert Wiebe was born in 1961. He has more than 30 years experience designing, implemenng, and tesng soware. He wrote his rst App in 1979, as a high school student, using 6502 assembler code on an Ohio Scienc C2-4P computer with 8k RAM. More recently, he has focused on developing games and ulies for Mac OS X. His interests include a vintage computer collecon which includes many pre-IBM PC era microcomputers; Apple Macintosh computers starng with the SE/30 running Mac OS 7 through to the Macbook Pro running Mac OS X that he uses today. He has developed many popular Mac OS X Apps including ShredIt X, NetShred X, Music Man, iVCD, and many more. He has experience developing soware in a number of industries, including mining, nance, and communicaons. He has worked for a number of employers including Motorola as a Senior Systems Architect developing two-way wireless data systems and Infowave Soware as the Soware Development Manager for their Imaging Division. Aer working for other people's companies, he founded his own companies, Mireth Technology and Burningthumb Soware, which are his primary interests today. He is also the author of Unity iOS Essenal book (ISBN 978-1-849691-82-6). I would like to thank my son, Abram, who is a beginning Mac OS X programmer himself, for always asking quesons. I would also like to thank my wife, Donna, for not only encouraging me but also for making it possible for me to pursue the things I want to do. And nally, I would like to thank my daughter, Amanda, who keeps me focused on the things that really maer in life. www.it-ebooks.info About the Reviewers Luca Bernardi is from Milan, Italy. He is 25 years old, has a degree in Computer Science and he is currently pursuing a Master's Degree in Soware Development and Design. Luca is a passion-driven iOS engineer and a mobile enthusiast, has developed applicaons that have been awarded as Apple's App of the Week and top selling app. When he's not programming he really enjoys learning new things, reading books, and sports such as basketball, snowboarding, and running. I want to thank my family, Malde, Claudio, Veronica and Adread who have always supported me, giving me everything I need to follow my passions. To my father, Giorgio, who passed away when I was a child, who gave me my rst computer, an Apple II, and taught me to always follow my passion. To my amazing girlfriend, Veronica, who always has a smile for me. John Dumais has over 25 years of experience developing system and circuit simulaon soware on a wide variety of plaorms, including Mac OS X. He has been using Objecve-C since StepStone originally introduced it. Most recently, the reviewer has been developing system monitoring and control soware for iOS devices. The other book he has reviewed is: http://books.google.com/books/about/Visual_Programming_With_HP_VEE. html?id=lJRQPgAACAAJ www.it-ebooks.info Dominik Jaworek is an experienced SW professional living in Vancouver Area, Brish Columbia, with his wife and two kids. He has been working in mobile SW area for more than 14 years experiencing all aspects of Soware Engineering, starng from development through business analysis, product management and R&D management. He has also been involved in accessibility technologies and soluons, and parcipated and presented in the CSUN 2001 conference. Dominik loves the outdoors and he tries to take every opportunity for trips and hikes with his family. Also he has always been fascinated with and interested in cars so it's no surprise that with his engineering soul he is an avid motorsports fan. Jamie B. McHardy is originally from the Isle of Man. He has worked in the mobile telecommunicaons domain for over a decade. He has developed embedded middleware used in millions of devices globally on technologies ranging from communicaon protocols to audio playback to digital security. Now based in Vancouver, Canada, he is father to one, has a passion for General Aviaon and is due to wed his beauful ancé in the summer of '13. www.it-ebooks.info www.PacktPub.com Support les, eBooks, discount offers and more You might want to visit www.PacktPub.com for support les and downloads related to your book. Did you know that Packt oers eBook versions of every book published, with PDF and ePub les available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entled to a discount on the eBook copy. Get in touch with us at service@packtpub.com for more details. At www.PacktPub.com, you can also read a collecon of free technical arcles, sign up for a range of free newsleers and receive exclusive discounts and oers on Packt books and eBooks. TM http://PacktLib.PacktPub.com Do you need instant soluons to your IT quesons? PacktLib is Packt's online digital book library. Here, you can access, read and search across Packt's enre library of books. Why Subscribe? Fully searchable across every book published by Packt Copy and paste, print and bookmark content On demand and accessible via web browser Free Access for Packt account holders If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view nine enrely free books. Simply use your login credenals for immediate access. www.it-ebooks.info www.it-ebooks.info Table of Contents Preface 1 Chapter 1: Our First Program – SimpleCalc 7 Locang developer tools 8 Time for acon - Installing the Xcode App 8 Working with projects 8 Time for acon - creang the SimpleCalc Xcode project 9 Understanding the Xcode project template 14 Time for acon – examine the items in the project navigator 15 Conguring an Xcode project 17 Time for acon - conguring the SimpleCalc Xcode project 17 Running an App 21 Time for acon – run the SimpleCalc App 21 Customizing an Xcode template's interface 23 Time for acon – creang the SimpleCalc interface 23 Customizing an Xcode template's implementaon 32 Time for acon – implement the SimpleCalc behavior 32 Building an App 34 Time for acon – building and installing the SimpleCalc App 34 Summary 37 Chapter 2: Debugger – Finding and Fixing Problems 39 The Debug area in Xcode 40 Time for acon – displaying the Debug area in Xcode 40 The Debug area appears on its own 41 Time for acon - integer division by zero 42 Examining variable values in the debugger 45 Time for acon – examining a variable value 45 Unexpected App behavior – no debugger? 46 Time for acon – index out of range 46 www.it-ebooks.info [...]... need 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... Integrated Development Environment (IDE), called Xcode The code in this book has been developed and tested with Xcode 4.3 Cocoa frameworks The Cocoa frameworks consist of libraries, Application Programming Interfaces (APIs), and runtimes that form the development layer for all of Mac OS X By developing with Cocoa, we will be creating applications the same way Mac OS X itself is created Our application. .. and appearances of Mac OS X Using Cocoa with Xcode IDE is the best way to create native Mac applications Time for action - Installing the Xcode App For Mac OS X, Apple provides the Xcode IDE for free in the Mac OS X App store We are going to install the Xcode IDE so that we can start making our first App To do this, we need to follow these steps: 1 2 3 Access the Mac App store by clicking on the Apple... software like Gatekeeper on Mac OS X 10.8 What you need for this book You need a Mac OS X computer capable of running Mac OS X 10.7 or later Some App features require Mac OS X 10.8 You also need to install Xcode Version 4 from the Mac OS X App store Xcode is a free download Who this book is for This book is for people who are programming beginners and have a great idea for a Mac OS X app and need to get... version of Mac OS X that we want the App to run which icon that we want the App to display By default, Xcode will configure our project to run only on the latest version of Mac OS X with the generic App Icon Sometimes we may want our project to run on an earlier version of Mac OS X For example, if we want to give our software to someone with an older computer or if we want to put our software in the Mac App... Creating a user interface Implementing a Mac OS X App behavior Building and running a Mac OS X program www.it-ebooks.info Our First Program – SimpleCalc Locating developer tools Before we start to develop our first Mac OS X program, we need to locate the tools needed to create programs There are several different choices for software development on Mac OS X and the tools that we will select depend... customizing the full screen animation Summary What is the Mac developer program? What are the benefits of joining the Mac developer program? Access to Development Videos, including World Wide Developer Conferences sessions [ iv ] www.it-ebooks.info 252 252 252 254 254 259 259 265 267 272 272 274 274 280 282 282 283 Table of Contents Access to the Mac OS X Developer Library Access to the Apple bug reporter... 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: [9] www.it-ebooks.info Our First Program – SimpleCalc 2 When Xcode asks us to select a template, select Application under Mac OS X and Cocoa Application as the template... the Mac App store Index 284 284 284 284 284 293 [v] www.it-ebooks.info www.it-ebooks.info Preface Apple is taking the world by storm Their market share is growing faster than the industry average and has been for years So, 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. .. discover the fundamental aspects of OS X development while investigating innovative platform features to create a final product that takes advantage of some of the unique aspects of OS X You will learn how to use Xcode tools to create and share Mac OS X Apps and explore numerous OS X features including iCloud, multi-touch trackpad, and the iSight camera Using fundamental development concepts and innovative . www.it-ebooks.info Mac Application Development by Example Beginner's Guide A comprehensive and praccal guide, for absolute beginners, to developing your own App for Mac OS X Robert Wiebe BIRMINGHAM. will need a solid foundaon in app development to get the job done. Mac Applicaon Development by Example takes you through all the aspects of using the Xcode development tool to produce complete. developing your own App for Mac OS X Robert Wiebe BIRMINGHAM - MUMBAI www.it-ebooks.info Mac Application Development by Example Beginner's Guide Copyright © 2012 Packt Publishing All rights reserved.