Creating iPhone Apps with Cocoa Touch The Mini Missing Manual-MANTESH.pdf

(12435 KB) Pobierz
460132621 UNPDF
iPhone Apps
with Cocoa
Touch
Craig Hockenberry
Creating
460132621.005.png 460132621.006.png 460132621.007.png 460132621.008.png 460132621.001.png 460132621.002.png
Creating iPhone Apps with Cocoa Touch: The Mini Missing Manual
by Craig Hockenberry
Copyright © 2010 O’Reilly Media, Inc. All rights reserved.
Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North,
Sebastopol, CA 95472.
O’Reilly Media books may be purchased for educational, business, or sales
promotional use. Online editions are also available for most titles: safari.
oreilly.com. For more information, contact our corporate/institutional
sales department: 800-998-9938 or corporate@oreilly.com .
May 2010:
First Edition.
The Missing Manual is a registered trademark of O’Reilly Media, Inc. The
Missing Manual logo, and “The book that should have been in the box”
are trademarks of O’Reilly Media, Inc. Many of the designations used by
manufacturers and sellers to distinguish their products are claimed as
trademarks. Where those designations appear in this book, and O’Reilly
Media is aware of a trademark claim, the designations are capitalized.
While every precaution has been taken in the preparation of this book,
the publisher assumes no responsibility for errors or omissions, or for
damages resulting from the use of the information contained in it.
ISBN: 9781449388409
Table of Contents
Introduction........................................................................................v
Building.Your.First.iPhone.App....................................................... 1
Getting the Tools.............................................................................................................................1
Installing Xcode.......................................................................................................................3
Getting the iPhone SDK.........................................................................................................6
What Lies Ahead for the SDK? ...........................................................................................11
Exploring Your New Tools ...........................................................................................................15
Every Flashlight Needs a Parts List ....................................................................................15
Some Assembly Required ................................................................................................... 21
Taking It for a Run on Your Mac.........................................................................................23
Revision Decision .................................................................................................................26
The.Power.of.Brackets.................................................................... 33
Objective-C: The Nuts and Bolts for Your iPhone App............................................................34
The Land of Square Brackets..............................................................................................34
The Object of It All........................................................................................................................36
Telling Your Objects to Do Things ......................................................................................37
Masses of Classes.........................................................................................................................39
Classes in Detail....................................................................................................................40
The Methods Behind the Madness ............................................................................................45
Categorically Speaking ........................................................................................................46
Implementation: The Brains Behind the Beauty..............................................................48
Creating New Classes ..................................................................................................................50
Managing Memory.......................................................................................................................53
Take a nil Pill ........................................................................................................................56
Autorelease with Ease .........................................................................................................58
Properties and Dots .............................................................................................................60
460132621.003.png
Methods of Class ..........................................................................................................................62
Initializing Objects ........................................................................................................................64
Deallocation Location ..........................................................................................................65
Loops: For Better or For Worse .................................................................................................66
Your Exceptional Code.................................................................................................................67
Learn by Crashing ................................................................................................................69
Selector Projector .........................................................................................................................73
Show Your id ...............................................................................................................................75
Where to Go from Here ..............................................................................................................79
Developer Documentation..................................................................................................80
Learn To Be Lazy ..................................................................................................................84
Cocoa.Touch:.Putting.Objective-C.to.Work.................................. 87
Get in Cocoa Touch ......................................................................................................................88
The Big Three: Models, Views, Controllers...............................................................................89
Views ......................................................................................................................................91
Models ...................................................................................................................................91
Controllers.............................................................................................................................92
Value Objects ................................................................................................................................94
Let’s Get Primitive ................................................................................................................95
Objectiied .............................................................................................................................96
Collections...................................................................................................................................100
Copying in Depth ...............................................................................................................102
Property Lists ......................................................................................................................102
Mutable vs. Immutable..............................................................................................................103
Make It Mutable .................................................................................................................104
Protect Your Data ...............................................................................................................106
Delegation and Data Sources ...................................................................................................107
Targets and Actions .................................................................................................................... 110
User Interface: The Hard Way .......................................................................................... 112
User Interface: The Easy Way ........................................................................................... 119
Notiications ................................................................................................................................135
Singletons ....................................................................................................................................139
Singletons as Globals ........................................................................................................140
Where to Go from Here ............................................................................................................142
The Language of Design....................................................................................................142
Colophon.........................................................................................143
 
Introduction
Since the iTunes App Store’s launch in July 2008, developers have
submitted over 100,000 iPhone applications to the store, resulting
in over 3 billion downloads and climbing. Who wouldn’t want a
piece of that action?
Before the app store was launched, iPhone app development was
limited to the engineers at Apple headquarters in Cupertino, Cali-
formia. Now that Apple has released the developer tools to anyone
who wants to download them, thousands of developers have
discovered how easy and fun it is to write software for the iPhone.
If you’ve done any programming in C or a related language like
C++, Java, PHP, or Perl, you can learn to write iPhone apps in a
snap. Objective-C will feel wonderfully familiar, since its entire
infrastructure is based on standard C.
In iPhone App Development: The Mini Missing Manual , you’ll create
your first iPhone app right from the get-go, and get up to speed
fast on all of your tools—Cocoa Touch, Interface Builder, Xcode,
and Objective-C.
Tip: There’s more to producing your own app than just writing
the code. This eBook is ideal if the Cocoa Touch programming
interface is all you want help with. For the full story on creating
and selling a successful app—designing, programming, trouble-
shooting, submitting, and marketing—check out iPhone App
Development: The Missing Manual . It covers everything in this
Mini Manual, plus the entire lifecycle of an iPhone app.
460132621.004.png
Zgłoś jeśli naruszono regulamin