Beginning iPhone 4 Development

Exploring the iOS SDK

By David Mark , Jack Nutting , Jeff LaMarche

Everything you need to know to develop your own best-selling iPhone and iPad apps, plus best practices for optimizing your code and delivering great user experiences.

Full Description

  • ISBN13: 978-1-4302-3024-3
  • 676 Pages
  • User Level: Beginner to Intermediate
  • Publication Date: January 27, 2011
  • Available eBook Formats: EPUB, MOBI, PDF
  • Print Book Price: $39.99
  • eBook Price: $27.99
Buy eBook Buy Print Book Add to Wishlist

Related Titles

Full Description

Beginning iPhone 4 Development is here! The authors of the bestselling Beginning iPhone 3 Development are back, with the same excellent material completely updated for iOS 4 and written from the ground up using the latest version of Apple's Xcode 3. All source code has been updated to use the latest Xcode templates and current APIs, and all-new screenshots show Xcode 3 in action.

Beginning iPhone 4 Development is a complete course in iOS 4 apps development. You’ll master techniques that work on iPhone, iPad, and iPod touch. We start with the basics, showing you how to download and install the tools you'll need, and how to create your first simple application. Next you’ll learn to integrate all the interface elements iOS users have come to know and love, such as buttons, switches, pickers, toolbars, and sliders. You’ll master a variety of design patterns, from the simplest single view to complex hierarchical drill-downs. The confusing art of table building will be demystified, and you’ll learn techniques to save and retrieve your data using SQLite, iPhone’s built-in database management system and Core Data, the standard for persistence that Apple brought to iOS with the release of SDK 3.

And there’s much more! You’ll learn to draw using Quartz 2D and OpenGL ES, add multitouch gestural support (pinches and swipes) to your applications, and work with the camera, photo library, accelerometer, and built-in GPS. You’ll discover the fine points of application preferences and learn how to localize your apps for multiple languages. You'll also learn how to use the new concurrency APIs included in iOS 4, and make robust multithreaded applications using Grand Central Dispatch.

  • The iPhone 4 update to the best-selling and most recommended book for Cocoa touch developers
  • Written in an accessible, easy-to-follow style
  • Full of useful tips and techniques to help you become an iOS pro

NOTE: For iPhone 4S or iOS 5 apps development, please instead check out the next edition of this book, Beginning iOS 5 Development - now available.

What you’ll learn

  • Everything you need to know to develop your own best-selling iPhone and iPad apps
  • Best practices for optimizing your code and delivering great user experiences
  • How to create “universal” apps for both iPhone and iPad

Who this book is for

Anyone who wants to start developing for iPhone, iPad, and iPod touch.

You can discover more about this book, download source code, and find support forums at the book's companion site, at www.iphonedevbook.com.

Table of Contents

Table of Contents

  1. Welcome to the Jungle
  2. Appeasing the Tiki Gods
  3. Handling Basic Interaction
  4. More User Interface Fun
  5. Autorotation and Autosizing
  6. Multiview Applications
  7. Tab Bars and Pickers
  8. Introduction to Table Views
  9. Navigation Controllers and Table Views
  10. iPad Considerations
  11. Application Settings and User Defaults
  12. Basic Data Persistence
  13. Grand Central Dispatch, Background Processing, and You
  14. Drawing with Quartz and OpenGL
  15. Taps, Touches, and Gestures
  16. Where Am I? Finding Your Way with Core Location
  17. Whee! Gyro and Accelerometer!
  18. iPhone Camera and Photo Library
  19. Application Localization
  20. Where to Next?
Source Code/Downloads

Downloads are available to accompany this book.

Your operating system can likely extract zipped downloads automatically, but you may require software such as WinZip for PC, or StuffIt on a Mac.

Errata

Please Login to submit errata.

On page 64:
"User interface controls come in three basic forms: active and passive" seems that "three" should be "two" ... or else a third basic form is missing.

"On an iOS device, many of the available controls can be used in all both ways" ... depending on the fix for the above error, it should either be "all" or "both" but not "all both."

On page 84:

In the section Adding Outlets and Actions, the newly added @property declaration for sliderLabel should be in a bold font because this is new code that the reader must type in.

On page 89:
when the program compiles is says that kSelectedSegmentIndex is undeclared

how should i declare it in the .m?

On page 106-107:
In each of the if (interfaceOrientation) statements the lines:

self.view.bounds = CGRectMake(); statements the parameters are incorrect in the book but correct in the download file.

On page 116:

CoreGraphics still needed to be linked in order to support CGAffineTransformIdentity, etc..

It might be just in XCode 4 beta 5, but I still had to do this...

On page 123:

In "Rotating out of here", the last line mentions that the user learned to link new frameworks into the project... but the section that mentions linking on page 116 states that its already included in the templates. No mention of how to actually link frameworks.

On page 137:
After the 3 bulleted items, and the first paragraph, there is some text missing.

On page 149:
First sentence of the fifth paragraph is,

"Drag a Round Rect Button from the library over to the."

I think the author means to complete the sentence with "view".

On page 152:

I think there is a small mistake in calling the correct method for the correct object. In the first part you are trying to load the Yellow View so the Blue should disappear. The code on this page is as follows:

[blueViewController viewWillAppear:YES];
[yellowViewController viewWillDisappear:YES];
[blueViewController.view removeFromSuperview];
[self.view insertSubview:yellowViewController.view atIndex:0];
[yellowViewController viewDidDisappear:YES];
[blueViewController viewDidAppear:YES];

I think it should be as follows:

[yellowViewController viewWillAppear:YES];
[blueViewController viewWillDisappear:YES];
[blueViewController.view removeFromSuperview];
[self.view insertSubview:yellowViewController.view atIndex:0];
[blueViewController viewDidDisappear:YES];
[yellowViewController viewDidAppear:YES];

Same thing in the 'else' statement.

On page 175:
Date picker shows a date one day later. This seems to be a known issue that has to do what the timezones. What I did to fix the problem was to use the NSDateFormatter as:


NSDate *selected = [datePicker date];

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];

[dateFormatter setTimeStyle:NSDateFormatterMediumStyle];
[dateFormatter setDateStyle:NSDateFormatterMediumStyle];

NSString *strDate = [dateFormatter stringFromDate:selected];


NSString *message = [[NSString alloc] initWithFormat:@"The date and time you selected is: %@", strDate];

And this worked!

On page 223:

Style inconsistency: In the code, there is no space between the "-" and the return type "(NSIndexPath *)".

On page 233:

The code listing for what needs to be added to CellsViewController.h is entirely in bold, so it is not immediately clear what is the newly added code, and what was already entered.

On page 253:
It should be - (UITableViewCell *)tableView:(UITableView *)TableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSUInteger section = [indexPath section]; NSUInteger row = [indexPath row];
You pressed - (UITableViewCell *)tableView:(UITableView *)a (#####There is needless 'a' #####) TableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSUInteger section = [indexPath section]; NSUInteger row = [indexPath row];

On page 319:

- (id)initWithCoder:(NSCoder *)coder { if (self = [super init]) { ....

I believe the condition in the if statement is missing an = sign as to test an equality as opposed to assigning [super init] to self

On page 420:

Lines which should be removed are not lined through, for instance #define kFilename @"data.plist" which gets immediately redefined as @"archive" in the next line.

Similarly, the assgnments to field1.text...field3.text in viewDidLoad should be lined out.

Also, it seems that under ARC, releasing objects is prohibited. Since this book is less than 1 year old, I would think many users would appreciate a short note in the errata addressing this very large change.

On page 678-683:

I've followed the code in this book to the letter, yet when I run the iphone simulation, the phone is not in landscape mode nor does the cube appear as it should. I've checked the codes on the the above mentioned pages and I copied them correctly. I can only assume that part of the code is missing from the book, I must also mention that I have the Ibook version.
Author Comment:

Chris,

You may want to register at the authors' site, where you will find further resources that may be of help to you:

http://www.iphonedevbook.com/