(Ebook) Programming in Objective-C, 4th Edition by Stephen Kochan ISBN 9780321811905, 0321811909 download
(Ebook) Programming in Objective-C, 4th Edition by Stephen Kochan ISBN 9780321811905, 0321811909 download
https://ebooknice.com/product/programming-in-objective-c-4th-
edition-10303844
https://ebooknice.com/product/programming-in-objective-c-21983726
https://ebooknice.com/product/programming-in-objective-c-2269318
https://ebooknice.com/product/programming-in-objective-c-2-0-1079786
https://ebooknice.com/product/biota-grow-2c-gather-2c-cook-6661374
(Ebook) Programming in C by Stephen G. Kochan ISBN
9780321776419, 0321776410
https://ebooknice.com/product/programming-in-c-10721148
(Ebook) Master SAT II Math 1c and 2c 4th ed (Arco Master the SAT
Subject Test: Math Levels 1 & 2) by Arco ISBN 9780768923049,
0768923042
https://ebooknice.com/product/master-sat-ii-math-1c-and-2c-4th-ed-arco-
master-the-sat-subject-test-math-levels-1-2-2326094
https://ebooknice.com/product/matematik-5000-kurs-2c-larobok-23848312
https://ebooknice.com/product/sat-ii-success-math-1c-and-2c-2002-peterson-
s-sat-ii-success-1722018
https://ebooknice.com/product/unix-shell-programming-21983808
www.it-ebooks.info
Programming in
Objective-C
Fourth Edition
www.it-ebooks.info
Developer’s Library
ESSENTIAL REFERENCES FOR PROGRAMMING PROFESSIONALS
Key titles include some of the best, most widely acclaimed books within their
topic areas:
PHP & MySQL Web Development Python Essential Reference
Luke Welling & Laura Thomson David Beazley
ISBN 978-0-672-32916-6 ISBN-13: 978-0-672-32978-4
MySQL PostgreSQL
Paul DuBois Korry Douglas
ISBN-13: 978-0-672-32938-8 ISBN-13: 978-0-672-32756-8
Linux Kernel Development C++ Primer Plus
Robert Love Stephen Prata
ISBN-13: 978-0-672-32946-3 ISBN-13: 978-0321-77640-2
Developer’s Library books are available at most retail and online bookstores, as well
as by subscription from Safari Books Online at safari.informit.com
Developer’s
Library
informit.com/devlibrary
www.it-ebooks.info
Programming in
Objective-C
Fourth Edition
Stephen G. Kochan
www.it-ebooks.info
Programming in Objective-C, Fourth Edition Acquisitions
Copyright © 2012 by Pearson Education, Inc. Editor
Mark Taber
All rights reserved. No part of this book shall be reproduced, stored in a retrieval system, or
transmitted by any means, electronic, mechanical, photocopying, recording, or otherwise, Development
without written permission from the publisher. No patent liability is assumed with respect to Editor
the use of the information contained herein. Although every precaution has been taken in Michael Thurston
the preparation of this book, the publisher and author assume no responsibility for errors or Managing Editor
omissions. Nor is any liability assumed for damages resulting from the use of the informa- Sandra Schroeder
tion contained herein.
Project Editor
ISBN-13: 978-0-321-81190-5 Mandie Frank
ISBN-10: 0-321-81190-9 Indexer
Heather McNeill
Library of Congress Cataloging-in-Publication Data
Proofreader
Kochan, Stephen G. Sheri Cain
Programming in objective-c / Stephen G. Kochan. -- 4th ed. Technical Editors
Wendy Mui
p. cm.
Michael Trent
ISBN 978-0-321-81190-5 (pbk.) Publishing
1. Objective-C (Computer program language) 2. Object-oriented Coordinator
Vanessa Evans
programming (Computer science) 3. Macintosh (Computer)--Programming.
Designer
I. Title. Gary Adair
QA76.64.K655 2012 Compositor
Mark Shirar
005.1'17--dc23
2011046245
Printed in the United States of America
Second Printing: March 2012
Trademarks
All terms mentioned in this book that are known to be trademarks or service marks have
been appropriately capitalized. Pearson cannot attest to the accuracy of this information.
Use of a term in this book should not be regarded as affecting the validity of any trademark
or service mark.
Bulk Sales
Pearson offers excellent discounts on this book when ordered in quantity for bulk
purchases or special sales. For more information, please contact
U.S. Corporate and Government Sales
1-800-382-3419
corpsales@pearsontechgroup.com
For sales outside of the U.S., please contact
International Sales
international@pearsoned.com
www.it-ebooks.info
❖
To Roy and Ve, two people whom I dearly miss.
www.it-ebooks.info
Contents at a Glance
1 Introduction 1
2 Programming in Objective-C 7
5 Program Looping 71
6 Making Decisions 93
8 Inheritance 151
19 Archiving 425
A Glossary 479
Index 493
www.it-ebooks.info
Contents
1 Introduction 1
What You Will Learn from This Book 2
How This Book Is Organized 3
Support 5
Acknowledgments 5
Preface to the Fourth Edition 6
2 Programming in Objective-C 7
Compiling and Running Programs 7
Using Xcode 8
Using Terminal 17
Explanation of Your First Program 19
Displaying the Values of Variables 23
Summary 25
Exercises 25
www.it-ebooks.info
viii Contents
5 Program Looping 71
The for Statement 72
Keyboard Input 79
Nested for Loops 81
for Loop Variants 83
The while Statement 84
The do Statement 88
The break Statement 90
The continue Statement 90
Summary 91
Exercises 91
6 Making Decisions 93
The if Statement 93
The if-else Construct 98
Compound Relational Tests 100
Nested if Statements 103
The else if Construct 105
The switch Statement 114
Boolean Variables 117
The Conditional Operator 122
Exercises 124
www.it-ebooks.info
Contents ix
8 Inheritance 151
It All Begins at the Root 151
Finding the Right Method 155
Extension Through Inheritance: Adding New Methods 156
A Point Class and Object Allocation 160
The @class Directive 161
Classes Owning Their Objects 165
Overriding Methods 169
Which Method Is Selected? 171
Abstract Classes 173
Exercises 174
www.it-ebooks.info
x Contents
www.it-ebooks.info
Contents xi
www.it-ebooks.info
xii Contents
www.it-ebooks.info
Contents xiii
19 Archiving 425
Archiving with XML Property Lists 425
Archiving with NSKeyedArchiver 427
Writing Encoding and Decoding Methods 429
Using NSData to Create Custom Archives 436
Using the Archiver to Copy Objects 439
Exercises 441
www.it-ebooks.info
xiv Contents
A Glossary 479
Index 493
www.it-ebooks.info
About the Author
Stephen Kochan is the author and coauthor of several bestselling titles on the C
language, including Programming in C (Sams, 2004), Programming in ANSI C (Sams, 1994),
and Topics in C Programming (Wiley, 1991), and several Unix titles, including Exploring
the Unix System (Sams, 1992) and Unix Shell Programming (Sams, 2003). He has been
programming on Macintosh computers since the introduction of the first Mac in 1984,
and he wrote Programming C for the Mac as part of the Apple Press Library. In 2003
Kochan wrote Programming in Objective-C (Sams, 2003), and followed that with another
Mac-related title, Beginning AppleScript (Wiley, 2004).
www.it-ebooks.info
We Want to Hear from You!
As the reader of this book, you are our most important critic and commentator.We value
your opinion and want to know what we’re doing right, what we could do better, what
areas you’d like to see us publish in, and any other words of wisdom you’re willing to
pass our way.
You can email or write directly to let us know what you did or didn’t like about this
book—as well as what we can do to make our books stronger.
Please note that we cannot help you with technical problems related to the topic of this book, and
that due to the high volume of mail we receive, we might not be able to reply to every message.
When you write, please be sure to include this book’s title and author, as well as your
name and phone or email address.
Email: feedback@developers-library.info
Mail: Reader Feedback
Addison-Wesley Developer’s Library
800 East 96th Street
Indianapolis, IN 46240 USA
Reader Services
Visit our website and register this book at www.informit.com/register for convenient
access to any updates, downloads, or errata that might be available for this book.
www.it-ebooks.info
1
Introduction
www.it-ebooks.info
2 Chapter 1 Introduction
When the iPhone was released in 2007, developers clamored for the opportunity to
develop applications for this revolutionary device. At first, Apple did not welcome third-
party application development.The company’s way of placating wannabe iPhone devel-
opers was to allow them to develop web-based applications. A web-based application
runs under the iPhone’s built-in Safari web browser and requires the user to connect to
the website that hosts the application in order to run it. Developers were not satisfied
with the many inherent limitations of web-based applications, and Apple shortly there-
after announced that developers would be able to develop so-called native applications for
the iPhone.
A native application is one that resides on the iPhone and runs under the iPhone’s
operating system, in the same way that the iPhone’s built-in applications (such as Con-
tacts, Stocks, and Weather) run on the device.The iPhone’s OS is actually a version of
Mac OS X, which meant that applications could be developed and debugged on a Mac-
Book Pro, for example. In fact,Apple soon provided a powerful Software Development
Kit (SDK) that allowed for rapid iPhone application development and debugging.The
availability of an iPhone simulator made it possible for developers to debug their applica-
tions directly on their development system, obviating the need to download and test the
program on an actual iPhone or iPod Touch device.
With the introduction of the iPad in 2010,Apple started to genericize the terminol-
ogy used for the operating system and the SDK that now support different devices with
different physical sizes and screen resolutions.The iOS SDK allows you to develop appli-
cations for any iOS device and as of this writing, iOS 5 is the current release of the oper-
ating system.
www.it-ebooks.info
How This Book Is Organized 3
So I decided neither to teach C first nor to assume prior knowledge of the language.
Instead, I decided to take the unconventional approach of teaching Objective-C and the
underlying C language as a single integrated language, from an object-oriented program-
ming perspective.The purpose of this book is as its name implies: to teach you how to
program in Objective-C. It does not profess to teach you in detail how to use the devel-
opment tools that are available for entering and debugging programs, or to provide in-
depth instructions on how to develop interactive graphical applications.You can learn all
that material in greater detail elsewhere, after you’ve learned how to write programs in
Objective-C. In fact, mastering that material will be much easier when you have a solid
foundation of how to program in Objective-C.This book does not assume much, if any,
previous programming experience. In fact, if you’re a novice programmer, with some
dedication and hard work you should be able to learn Objective-C as your first program-
ming language. Other readers have been successful at this, based on the feedback I’ve
received from the previous editions of this book.
This book teaches Objective-C by example.As I present each new feature of the lan-
guage, I usually provide a small complete program example to illustrate the feature. Just as
a picture is worth a thousand words, so is a properly chosen program example.You are
strongly encouraged to run each program (all of which are available online) and compare
the results obtained on your system to those shown in the text. By doing so, you will
learn the language and its syntax, but you will also become familiar with the process of
compiling and running Objective-C programs.
www.it-ebooks.info
Random documents with unrelated
content Scribd suggests to you:
The Project Gutenberg eBook of
Firemen and Their Exploits
This ebook is for the use of anyone anywhere in the United States
and most other parts of the world at no cost and with almost no
restrictions whatsoever. You may copy it, give it away or re-use it
under the terms of the Project Gutenberg License included with this
ebook or online at www.gutenberg.org. If you are not located in the
United States, you will have to check the laws of the country where
you are located before using this eBook.
Author: F. M. Holmes
Language: English
FIREMEN
AND THEIR EXPLOITS:
WITH SOME ACCOUNT
LONDON:
S. W. PARTRIDGE & CO.,
8 & 9, PATERNOSTER ROW.
1899.
PREFACE.
CHAP. PAGE
THE HORSED FIRE-ESCAPE APPEARS. AN EXCITING
I. 9
SCENE
THE BEGINNING OF THE STORY. HERO'S "SIPHON." HOW
II. 17
THE ANCIENTS STROVE TO EXTINGUISH FIRES
III. IN MEDIÆVAL DAYS. AN EPOCH-MAKING FIRE 20
THE PEARL-BUTTON MAKER'S CONTRIVANCE. THE
IV. 36
MODERN FIRE-ENGINE
EXTINGUISHMENT BY COMPANY. THE BEGINNINGS OF
V. 47
FIRE INSURANCE
VI. THE STORY OF JAMES BRAIDWOOD 53
VII. THE THAMES ON FIRE. THE DEATH OF BRAIDWOOD 58
VIII. A PERILOUS SITUATION. CAPTAIN SHAW.
VIII. IMPROVEMENTS OF THE METROPOLITAN BOARD AND OF 67
THE LONDON COUNTY COUNCIL
IX. A VISIT TO HEADQUARTERS 83
X. HOW RECRUITS ARE TRAINED 98
XI. SOME STORIES OF THE BRIGADE 111
XII. FIRE-ESCAPES AND FIRE-FLOATS 123
CHEMICAL FIRE-ENGINES. FIRE-PROOFING, OR MUSLIN
XIII. 134
THAT WILL NOT FLAME
THE WORK OF THE LONDON SALVAGE CORPS. THE
XIV. 144
GREAT CRIPPLEGATE FIRE
XV. ACROSS THE WATER 156
OFF TO THE FIRE.
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebooknice.com