Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Mac Application Development by Example: Beginner's Guide
Mac Application Development by Example: Beginner's Guide

Mac Application Development by Example: Beginner's Guide: A comprehensive and practical guide, for absolute beginners, to developing your own App for Mac OS X book and ebook.

eBook
$26.09 $28.99
Paperback
$48.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with Print?

Product feature icon Instant access to your digital copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Redeem a companion digital copy on all Print orders
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Table of content icon View table of contents Preview book icon Preview Book

Mac Application Development by Example: Beginner's Guide

Chapter 2. Debugger – Finding and Fixing Problems

This book is not about finding and fixing problems – known as debugging. However, sometimes the debugging tool can appear unexpectedly or our App will not do what we want and we may want to see the debugging tool. So it's important to be able to recognize the debugger and figure out what to do next. Knowing how to respond to the unexpected appearance of the debugger and knowing how to use the debugger to figure out why our App is not behaving correctly can really make our lives easier.

In this chapter, we shall learn the following:

  • Recognizing the Debug area in Xcode

  • What kind of problems can result in the Debug area appearing and Xcode showing us the problem

  • Examining program variables in the debugger

  • What kinds of common problems can result in the Debug area appearing or unexpected App behavior without Xcode showing us the problem

  • How to interpret what the debugger is trying to tell us and getting Xcode to show us the problem

The Debug area in Xcode


The main Xcode window is split into panes. Typically, when we launch Xcode, the Debug area is not visible. We can either wait for the debugger to appear on its own, which it will due to some program errors, or we can show the debugger area manually and familiarize ourselves with where the Debug area will appear in Xcode.

Time for action – displaying the Debug area in Xcode


If we want to manually display the debugger area in Xcode, we can do so by clicking the correct icon in the Xcode toolbar. The setting is on a per project basis so if we display the debugger area in one project it will not be visible in another project, unless we also make it visible in the second project.

  1. In the Xcode project window toolbar, locate the Hide or show the Debug area button in the View tools as shown in the following screenshot:

  2. Click the Hide or show the Debug area button in the View tools to reveal the Debug area as shown in the following screenshot:

What just happened?

By manually displaying the Debug area we can see where it will appear in the Xcode window. If we are running our App and Xcode ever brings itself forward, in front of our App, we should look in the Debug area to see if our App has an error that has caused the debugger to take control.

The Debug area appears on its own


There are a few kinds of programming errors that will cause the Debug area to be displayed. These problems are critical errors such as trying to access memory that does not belong to your program, dividing integer values by zero, or trying to access objects that have been released or garbage collected (dangling pointers).

Time for action - integer division by zero


We can make a small change to the SimpleCalc program to demonstrate an integer division by zero that results in the Debug area appearing while the program is running.

  1. Create a new Xcode project (we can follow the steps given in Chapter 1, Our First Program – SimpleCalc) but call it BuggyCalc instead of SimpleCalc. Other than the App name being BuggyCalc, all the steps are the same as was done for SimpleCalc.

    Tip

    The complete project for BuggyCalc is included in the downloadable content for this book so if you don't want to create BuggyCalc yourself, you can just download the project and open it in Xcode.

  2. In BuggyCalc, select the filename BTSAppDelegate.m and add the following line of code that uses the compiler directive #define to create a symbol named D_SHOW_DIVIDEBYZERO_BUG with a value of 1:

    #define D_SHOW_DIVIDEBYZERO_BUG 1

    Tip

    If you are using the pre-built project, locate the line of code that defines the symbol and change its value from 0 to...

Examining variable values in the debugger


Sometimes, when our App ends up in the debugger, we need to look at the values of the variables to determine what is wrong. Once we can see the value that a variable contains the reason for the program problem becomes obvious.

Time for action – examining a variable value


Since BuggyCalc has crashed, and Xcode has brought itself to the foreground with the Debug area displayed, we can take this opportunity to look at some of the information that is available in the debugger:

  1. Look more closely at the Debug area. You will see it has two panes. On the left-hand side is the variable view and on the right-hand side is the console as shown in the following screenshot:

  2. By looking in the variable view, we can see the actual values that are in our variables when the program ended up in the debugger.

  3. Drag the top of the Debug area up, to make the view larger.

  4. Click on the disclosure triangle beside self to display all the member variables for our AppDelegate as shown in the following screenshot:

What just happened?

When our App was stopped in the debugger we were able to examine the values of variables in the buttonAction: method that were causing the problems. We were also able to examine the variables for the AppDelegate.

There...

Unexpected App behavior – no debugger?


There are many more programming errors that will cause the App to behave in an unexpected way but the Debug area will not be displayed. These problems are for less critical errors. Less critical errors include things such as:

  • Including a parameter in a known message but with an invalid value

  • Sending a message to an object that does not know how to handle that message

Time for action – index out of range


We can make a small change to the SimpleCalc program to demonstrate an index out of range that will cause our BuggyCalc App to misbehave, but will not automatically display the Debug area. For this type of error, we can create something called a breakpoint, which will force the Debug area to appear when the error occurs.

  1. In BuggyCalc, select the filename BTSAppDelegate.m and set the value of D_SHOW_DIVIDEBYZERO_BUG to 0.

  2. Add one line of code that uses the compiler directive #define to create a symbol named D_SHOW_INDEXOUTOFRANGE_BUG with a value of 1 as shown in the following code snippet:

    #define D_SHOW_DIVIDEBYZERO_BUG 0
    #define D_SHOW_INDEXOUTOFRANGE_BUG 1
  3. Locate the - (IBAction)myButtonAction:(id)a_sender method and add the following lines of code, to create an array of operators, in the method. These should be the first lines of code in the implementation:

        // Use an array to hold the valid operations
        NSArray *l_validOperations = [NSArray arrayWithObjects...

Using breakpoints to get more information from Xcode


When our App does not behave as expected, and we see console messages in the Debug area we can use something called a breakpoint to cause Xcode to reveal the line at which our program code caused the problem. Once we have identified the exact location and cause of the problem, it becomes much easier to fix Apps that do not behave as expected.

Time for action – set a breakpoint


We can add a breakpoint to the BuggyCalc App to cause Xcode to identify the exact line of program code that is causing the index out of range error.

  1. In BuggyCalc, select the filename BTSAppDelegate.m and make sure the value of D_SHOW_DIVIDEBYZERO_BUG is 0 and the value of D_SHOW_INDEXOUTOFRANGE_BUG is 1.

  2. In the Xcode navigator pane, click on the icon to Show the Breakpoint navigator as shown in the following screenshot:

  3. In the Xcode navigator pane, click on the + icon and select the menu item titled Add ExceptionBreakpoint… as shown in the following screenshot:

  4. In the Xcode navigator pane, on the breakpoint options window, select Done to accept the default settings for the exception breakpoint as shown in the following screenshot:

  5. Click on the Run icon again to launch BuggyCalc.

  6. Click on the ÷ button.

What just happened?

When we clicked on ÷ our program misbehaved, just as before, but this time Xcode became the foreground App and indicated the exact line in our...

Summary


In this chapter, we have learned to both recognize the debugger and recognize when our App is not behaving, so that if the debugger appears or our App misbehaves we know how to find and fix the problem. We know that as beginning programmers, we don't need to know everything about the debugger but we do need to be able to recognize when the debugger shows up and how it can be used to help us identify the problem with our program code.

Specifically, we covered how to recognize when the debugger appears on its own and how to force our App into the debugger if it is not behaving correctly. We also covered how the debugger can be used to look at the values of our variables.

Now that we've learned how to recognize the debugger, we can take a look at a more advanced programming topic and learn how to build our own System Preference – which is the topic of the next chapter.

Left arrow icon Right arrow icon

Key benefits

  • Start developing applications for Mac OS X
  • Learn how to take advantage of Mac features such as the iSight camera and the multi-touch trackpad
  • Use Xcode to its full potential to make tasks simpler

Description

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.

Who is this book 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 started.

What you will learn

  • The basic concepts and tools and how to use them to create an OS X application
  • Access information from the Internet from within a business app to enhance its functionality
  • Store and retrieve information from Apple s iCloud server farm
  • Use the debugger to find and fix problems that cause an app to crash
  • Create a new System Preference that can change the fundamental way the Mac OS system behaves
  • Capture video from the iSight camera and save it as a Quicktime movie file
  • Implement a custom view and draw directly into it using the 2D drawing interfaces
  • Share your app with others in a Gatekeeper-aware and friendly manner
Estimated delivery fee Deliver to United States

Economy delivery 10 - 13 business days

Free $6.95

Premium delivery 6 - 9 business days

$21.95
(Includes tracking information)

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Dec 21, 2012
Length: 318 pages
Edition : 1st
Language : English
ISBN-13 : 9781849693820
Vendor :
Apple
Category :
Languages :
Tools :

What do you get with Print?

Product feature icon Instant access to your digital copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Redeem a companion digital copy on all Print orders
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Estimated delivery fee Deliver to United States

Economy delivery 10 - 13 business days

Free $6.95

Premium delivery 6 - 9 business days

$21.95
(Includes tracking information)

Product Details

Publication date : Dec 21, 2012
Length: 318 pages
Edition : 1st
Language : English
ISBN-13 : 9781849693820
Vendor :
Apple
Category :
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 103.98
Mac Application Development by Example: Beginner's Guide
$48.99
iOS and OS X Network Programming Cookbook
$54.99
Total $ 103.98 Stars icon

Table of Contents

10 Chapters
Our First Program – SimpleCalc Chevron down icon Chevron up icon
Debugger – Finding and Fixing Problems Chevron down icon Chevron up icon
System Preferences – NewDefaults Chevron down icon Chevron up icon
Business Application – Global Currency Converter Chevron down icon Chevron up icon
Personal Information – Numbers in the iCloud Chevron down icon Chevron up icon
Painting – Multi-finger Paint Chevron down icon Chevron up icon
Capturing Still Images – iSight iMage cApture App Chevron down icon Chevron up icon
Video Recording – iSight Recorder Chevron down icon Chevron up icon
Video Recording – Full Screen iSight Recorder Chevron down icon Chevron up icon
Sharing Our App with Others – Becoming a Mac Developer Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.5
(2 Ratings)
5 star 0%
4 star 50%
3 star 50%
2 star 0%
1 star 0%
Aaron Feb 28, 2013
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
I'm not sure if the same thing is true for the print version of this book but when I went to my PacktPub.com account to download this book to put on my iPad, I found that they had the examples bundled up in a .zip file that I could download, why can't more books do this?! I often find that you end up copying out of the book and it either doesn't work or that you have not properly digested how it works. The advantage of having these demos ready to download is that you can straight away get working code which you can tear apart, change, modify and really get your hands on. I often find this the best learning approach, but it is not for everyone. The book does not cater either way (in a good way) if you want to learn step-by-step then you can, the book guides you though exactly how to do things and more importantly it explains to you what you are writing, why you need it and what it does for the application.Now I was testing out the ePub format on my iPad and did find a few formatting errors with the way the text and tables flow from page to page but it did not effect how the book read at all.I am fairly unfamiliar with the Xcode interface and I only know the basic locations of the popular buttons, I think the interface can be a little bit daunting to some. This book starts right at the beginning and does not expect you to know anything about the interface beforehand, it walks you through all of the things that you need to know and some of the others you will pickup along the way.One thing I did find really useful about the book is the fact that it is laid out in almost three simple steps for each part, it first walks through a little bit about what you are about to do and what it will do for the application, it then has a `Time for action' step which guides you through the actual process, and then the part that I like the most is the `What just happened?' part. That last part is something that I have found lacking in some of the other books I have read (not all though) is that they don't take the time to step back and pause for a second and explain exactly what you just did.
Amazon Verified review Amazon
Ted Nov 01, 2013
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
OK for beginners, but be aware of a couple of issues:Apple has changed a few things in Xcode 5.0 (latest version for Mavericks), which are not represented correctly in the book. One tricky item in particular is how outlets are assigned in IB for items in the view. The method in the book is no longer supported, so you will have to do some googling.Also, there are a lot of typo's, and missing lines of code in the book examples. If you want to compile and run the code as listed, you will have to add a few things. Not good for a beginner.I will admit, I have not downloaded the .zip file that is supposed to be available to see if that has the correct source code. So far I am on chapter 5 and have been able to figure out how to fix all the issues, as they are minor if you have some experience with XCode. If you are a true beginner, you may struggle with this.Other than those issues, I like the layout of actually creating working applications for each chapter, rather than theoretical ideas.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is the digital copy I get with my Print order? Chevron down icon Chevron up icon

When you buy any Print edition of our Books, you can redeem (for free) the eBook edition of the Print Book you’ve purchased. This gives you instant access to your book when you make an order via PDF, EPUB or our online Reader experience.

What is the delivery time and cost of print book? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela
What is custom duty/charge? Chevron down icon Chevron up icon

Customs duty are charges levied on goods when they cross international borders. It is a tax that is imposed on imported goods. These duties are charged by special authorities and bodies created by local governments and are meant to protect local industries, economies, and businesses.

Do I have to pay customs charges for the print book order? Chevron down icon Chevron up icon

The orders shipped to the countries that are listed under EU27 will not bear custom charges. They are paid by Packt as part of the order.

List of EU27 countries: www.gov.uk/eu-eea:

A custom duty or localized taxes may be applicable on the shipment and would be charged by the recipient country outside of the EU27 which should be paid by the customer and these duties are not included in the shipping charges been charged on the order.

How do I know my custom duty charges? Chevron down icon Chevron up icon

The amount of duty payable varies greatly depending on the imported goods, the country of origin and several other factors like the total invoice amount or dimensions like weight, and other such criteria applicable in your country.

For example:

  • If you live in Mexico, and the declared value of your ordered items is over $ 50, for you to receive a package, you will have to pay additional import tax of 19% which will be $ 9.50 to the courier service.
  • Whereas if you live in Turkey, and the declared value of your ordered items is over € 22, for you to receive a package, you will have to pay additional import tax of 18% which will be € 3.96 to the courier service.
How can I cancel my order? Chevron down icon Chevron up icon

Cancellation Policy for Published Printed Books:

You can cancel any order within 1 hour of placing the order. Simply contact customercare@packt.com with your order details or payment transaction id. If your order has already started the shipment process, we will do our best to stop it. However, if it is already on the way to you then when you receive it, you can contact us at customercare@packt.com using the returns and refund process.

Please understand that Packt Publishing cannot provide refunds or cancel any order except for the cases described in our Return Policy (i.e. Packt Publishing agrees to replace your printed book because it arrives damaged or material defect in book), Packt Publishing will not accept returns.

What is your returns and refunds policy? Chevron down icon Chevron up icon

Return Policy:

We want you to be happy with your purchase from Packtpub.com. We will not hassle you with returning print books to us. If the print book you receive from us is incorrect, damaged, doesn't work or is unacceptably late, please contact Customer Relations Team on customercare@packt.com with the order number and issue details as explained below:

  1. If you ordered (eBook, Video or Print Book) incorrectly or accidentally, please contact Customer Relations Team on customercare@packt.com within one hour of placing the order and we will replace/refund you the item cost.
  2. Sadly, if your eBook or Video file is faulty or a fault occurs during the eBook or Video being made available to you, i.e. during download then you should contact Customer Relations Team within 14 days of purchase on customercare@packt.com who will be able to resolve this issue for you.
  3. You will have a choice of replacement or refund of the problem items.(damaged, defective or incorrect)
  4. Once Customer Care Team confirms that you will be refunded, you should receive the refund within 10 to 12 working days.
  5. If you are only requesting a refund of one book from a multiple order, then we will refund you the appropriate single item.
  6. Where the items were shipped under a free shipping offer, there will be no shipping costs to refund.

On the off chance your printed book arrives damaged, with book material defect, contact our Customer Relation Team on customercare@packt.com within 14 days of receipt of the book with appropriate evidence of damage and we will work with you to secure a replacement copy, if necessary. Please note that each printed book you order from us is individually made by Packt's professional book-printing partner which is on a print-on-demand basis.

What tax is charged? Chevron down icon Chevron up icon

Currently, no tax is charged on the purchase of any print book (subject to change based on the laws and regulations). A localized VAT fee is charged only to our European and UK customers on eBooks, Video and subscriptions that they buy. GST is charged to Indian customers for eBooks and video purchases.

What payment methods can I use? Chevron down icon Chevron up icon

You can pay with the following card types:

  1. Visa Debit
  2. Visa Credit
  3. MasterCard
  4. PayPal
What is the delivery time and cost of print books? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela
Modal Close icon
Modal Close icon