Objective-C Programming_ The Big Nerd Ranch Guide - Aaron Hillegass [0]
Aaron Hillegass
Copyright © 2011 Big Nerd Ranch, Inc.
All rights reserved. Printed in the United States of America. This publication is protected by copyright, and permission must be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permissions, contact
Big Nerd Ranch, Inc.
154 Krog Street
Suite 100
Atlanta, GA 30307
(404) 478-9005
http://www.bignerdranch.com/
book-comments@bignerdranch.com
The 10-gallon hat with propeller logo is a trademark of Big Nerd Ranch, Inc.
Exclusive worldwide distribution of the English edition of this book by
Pearson Technology Group
800 East 96th Street
Indianapolis, IN 46240 USA
http://www.informit.com
The authors and publisher have taken care in writing and printing this book but make no expressed or implied warranty of any kind and assume no responsibility for errors or omissions. No liability is assumed for incidental or consequential damages in connection with or arising out of the use of the information or programs contained herein.
App Store, Apple, Cocoa, Cocoa Touch, Instruments, Interface Builder, iOS, iPad, iPhone, iTunes, iTunes Store, Mac, Mac OS, Objective-C, and Xcode are trademarks of Apple, Inc., registered in the U.S. and other countries.
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 the publisher was aware of a trademark claim, the designations have been printed with initial capital letters or in all capitals.
Print ISBN-10 0321706285
Print ISBN-13 978-0321706287
Library of Congress Control Number: 2011931707
First printing, November 2011
Acknowledgments
It is a great honor that I get to work with such amazing people. Several of them put a lot of time and energy into making this book great. I’d like to take this moment to thank them.
Mikey Ward wrote several chapters of this book including Your First iOS Application, Your First Cocoa Program, and Blocks. If I were a nicer boss, I would have put his name on the cover.
The other instructors who teach the Objective-C materials fed us with a never-ending stream of suggestions and corrections. They are Scott Ritchie, Mark Fenoglio, Brian Hardy, Christian Keur, and Alex Silverman.
My tireless editor, Susan Loper, took my stream-of-consciousness monologue that stumbled across everything a programmer needs to know and honed it into an approachable primer.
Several technical reviewers helped me find and fix flaws. They are James Majors, Mark Dalrymple, Scott Steinman, Bart Hoffman, Bolot Kerimbaev, and Nate Chandler.
Ellie Volckhausen designed the cover.
Chris Loper at IntelligentEnglish.com designed and produced the EPUB and Kindle versions.
The amazing team at Pearson Technology Group patiently guided us through the business end of book publishing.
Table of Contents
I. Getting Started
1. You and This Book
C and Objective-C
How this book works
How the life of a programmer works
2. Your First Program
Installing Apple’s developer tools
Getting started with Xcode
Where do I start writing code?
How do I run my program?
So what is a program?
Don’t stop
II. How Programming Works
3. Variables and Types
Types
A program with variables
Challenge
4. if/else
Boolean variables
else if
For the More Curious: Conditional (ternary) operator
Challenge
5. Functions
When should I use a function?
How do I write and use a function?
How functions work together
Local variables, frames, and the stack
Recursion
Looking at the frames in the debugger
return
Global and static variables
Challenge
6. Numbers
printf()
Integers
Tokens for displaying integers
Integer