... Objective -C
on the Mac
ForiOSandOS X
Scott Knaster
Waqar Malik
Mark Dalrymple
v
Contents at a Glance
Foreword xvii
About the Authors xix
About the Technical Reviewer xxi
Acknowledgments xxiii
Working ... book’s source code, go to www.apress.com/source-code/.
vii
Contents
Foreword xvii
About the Authors xix
About the Technical Reviewer xxi
Acknowledgments xxiii
Working with This Book xxv
Chapter ... Counting 159
Being Exceptional 170
Keywords for Exceptions 171
Catching Different Types of Exceptions 172
Throwing Exceptions 172
Exceptions Need Memory Management Too 174
Exceptions and Autorelease...
... Cocoa and Cocoa Touch.
Learn C, Objective -C, and Cocoa, and you will have everything you need to
develop even the most complex Macintosh applications. Learn C, Objective -C,
and Cocoa Touch, ... applications that feature
the Mac look -and- feel with buttons, scroll bars, and windows, you’ll need to
finish this book, then learn Objective -C and Cocoa (for the Mac) or Cocoa Touch
(for iOS ... into machine codes that the computer
would execute. Before that, most people thought computers could only add numbers.
Controlling Execution
So how do you use the Xcode debugger to control...
...
located in the 02.01 - Hello Objective- C folder.
To create the project, start by launching Xcode. You can find the Xcode appli-
cation in /Developer/Applications. We put the Xcode icon in the ... beneath the user interface,
such as data structures and communication mechanisms. All the programs in this book are
based onthe Foundation framework.
Learn Objective -C onthe Mac
Copyright ... indicate a file that holds Objective- C code and will be pro-
cessed by the Objective- C compiler. File names ending in .c are handled by theC compiler,
and .cpp files are the province of the C+ +...
... Yesterday
Cocoa and Objective -C are at the heart of Apple’s OSXandiOS operating systems. Although
OS Xand especially iOS are relatively new, Objective -C and Cocoa are much older. Brad Cox
invented ... running.
2. Select File ➤ New ➤ New Project.
3. Choose Application onthe left and Command Line Tool onthe right.
4. Click Next.
5. Type BOOL Party as the Project Name, and click Next.
6. Click Create.
Edit ... embrace
Objective -C.
Getting Ready
Xcode is the development environment provided by Apple for creating iOSandOSX
applications. Macs don’t come with Xcode preinstalled, but downloading and...
... (for iOS) toolkits. Cocoa and Cocoa Touch are written in Objective -C
and contain all the elements of theOSXandiOS user interfaces, plus a whole lot more. Once
you learn Objective -C, you’ll ...
most) applications that have a true OSX or iOS look and feel.
In addition to presenting Objective -C, this book introduces you to its companion, Apple’s Cocoa
(for OS X) and Cocoa Touch (for ... Store icon in the dock
Figure 1-2. Search for Xcode in theMac App Store
www.it-ebooks.info
Chapter 2: Extensions to C
17
Creating the project for BOOL Party is exactly the same process as...
... of what you clicked on, and links to related
documentation. Altogether, the documentation contained within Xcode is the ultimate
encyclopedic reference to Cocoa, Xcode, and all other Apple development ... matrix generally requires multiple
clicks. The first click selects the matrix, then a second click tells the matrix that you want
to focus on its insides, andthe third click actually selects the ... application is launched. This function contains only one line of code, which
calls a function named NSApplicationMain(). That function, which is part of Cocoa,
automatically creates an instance...
... own OS 9. As you will see, the core components of OSX — Cocoa, Mach,
IOKit, the XCode Interface Builder, and others — are all direct descendants of NeXTSTEP. The
fusion of two fringe, niche ... Advanced functions (such as repair, or HFS+/HFSX conversion) will require write access.
flast.indd xxxflast.indd xxx 9/29/2012 5:55:35 PM9/29/2012 5:55:35 PM
xxxii
INTRODUCTION
TABLE I-1: Host ... specifying which demo is based on
which device and OS, the shell command prompt has been left as is, and by the hostname you can
easily fi gure out which version of OSX or iOSthe demo can...
... finishing touches to our
application, then run it. We’re almost there!
Creating the Application Icon
One thing that all applications need is an icon. MacOSX uses a special format for icons that ...
https://developer.apple.com/library /mac/ documentation/Cocoa/Conceptual/ObjectiveC/ObjC.pdf.
Declaring Actions
As noted in the previous chapter, actions are Objective -C methods that can be invoked directly
from the ... When the New Project
Assistant comes up (Figure 2-1), select Application from under theMacOSX heading in the left
column, then select the Cocoa Application icon from the upper-right pane and...
... when the task is not yet executed:
dispatch_async function
Executes a block object on a dispatch queue.
dispatch_async_f function
Executes a C function on a dispatch queue.
The dispatch_sync method ... 2).
dispatch_after_f
Dispatches a C function to GCD for execution after a given period of time, specified
in nanoseconds. This function accepts four parameters:
Delay in nanoseconds
The number of nanoseconds GCD has ... constructing traditional C functions, as we will
see in “Constructing Block Objects and Their Syntax” on page 2. Block objects can
1
For more information about our books, courses, conferences, and news,...
... queues for synchro-
nous execution. The next section shows asynchronous execution on concurrent
queues, while “Constructing Your Own Dispatch Queues” on page 43 will show how
to execute tasks synchronously ... optimization, this function invokes the block onthe current thread when possible.
—Grand Central Dispatch (GCD) Reference
To execute a C function instead of a block object, synchronously, on a dispatch ... block object on a dispatch queue.
dispatch_async_f function
Executes a C function on a dispatch queue.
The dispatch_sync method cannot be called onthe main queue because
it will block the thread...