Book Image

Xcode 4 Cookbook

By : Steven F. Daniel
Book Image

Xcode 4 Cookbook

By: Steven F. Daniel

Overview of this book

<p>The release of iOS 6 comes packed with over 1,500 new APIs and 200 new features. Xcode 4 Cookbook will teach youhow to integrate iCloud storage and how to go about using the Facebook and OpenGraphi APIs, as well as providing you with practical step-by-step recipes covering User Interfaces, data management, multimedia, localisation services and maps, right through to application deployment to the Apple App Store. You will soon be mastering the technology and the skills needed to create some amazing applications.<br /><br />"Xcode 4 Cookbook" will help you learn how to build some powerful applications using iOS 6 and the various frameworks. You will soon master how to incorporate iCloud, Facebook, and the OpenGraph APIs and apply various image filters and transitions using Core Image integration within your applications. By using the book’s step-by-step approach, you will soon master the technology and the skills needed to create some amazing applications.<br /><br />"Xcode 4 Cookbook" provides you with the skills and knowledge and practical recipes on how to go about developing useful applications that can be used within the industry.<br /><br />You will start by learning how to go about downloading and installing the Xcode Development Tools, learn about Interface Builder to create the visual user interfaces, connecting the objects using Outlets and Actions, and learn how to compile/debug your applications.<br /><br />Finally, you will learn how to capture media with the iOS camera and play back video content using Airplay to wirelessly stream videos to an Apple TV device, using the AV Foundation framework, as well as using the Core Image and Core Graphics frameworks to create amazing image effects using the built-in features.</p>
Table of Contents (19 chapters)
Xcode 4 Cookbook
Credits
About the Author
Acknowledgement
About the Reviewers
www.PacktPub.com
Preface
Index

Preface

The Xcode 4 Cookbook provides you with the skills and knowledge, and practical recipes on how to go about developing useful applications that can be used within the industry. By using this cookbook's step-by-step style approach, presenting examples in the style of recipes, allowing you to go directly to your topic of interest, or follow topics throughout a chapter to gain in-depth knowledge, you will gain the skills needed to develop some stunning applications.

This cookbook is a practical guide featuring over 100 recipes that show you how to build your own fun and exciting iOS applications by integrating iCloud, Facebook, Mobile core services, Core Image and Media Player Frameworks, and the Core Graphics and Core Motion frameworks, that will enable you to enhance your applications to create some amazing image and transition effects using the built-in image filters.

In this book, I have tried my best to keep the code simple and easy to understand. I have provided step-by-step instructions with loads of screenshots at each step to make it easier to follow. You will soon be mastering the different aspects of iOS 6 programming, as well as mastering the technology and skills needed to create some stunning applications.

Feel free to contact me at for any queries, or if you just want to drop by and say "Hello". Any suggestions for improving this book will be highly regarded.

What this book covers

Chapter 1, Getting and Installing the iOS SDK Development Tools, introduces the developer to the Xcode developer set of tools, as well as the capabilities of the iOS Simulator and each of the layers contained within the iOS architecture, before finally looking at how to create a simple Hello World iOS application.

Chapter 2, User Interfaces – Creating the UI, introduces the concept of views and how they are part of a complete iOS application. Exploring a large number of various view components, you will create different applications that will help you understand how each component works. We will also learn about the Model View Controller (MVC) pattern and how to use it to create applications suitable for enhanced user experience. Through this chapter, you will also learn about the most useful controllers, which will be part of many of your projects in the future.

Chapter 3, Using Storyboards, gains an understanding of what Storyboards are and how we can apply the various transitions between views. We will take a look into how we are able to create and configure scenes and storyboard files, to present these programmatically. Finally, we will learn how to integrate Twitter capabilities into our application to tweet photos and standard messages using the new iOS 6 Social frameworks.

Chapter 4, Using Xcode Instruments, focuses on how to effectively use Instruments within our applications to track down memory leaks and eliminate bottlenecks that could potentially cause our application to crash on the user's iOS device. We will also take a look at how to add and configure instruments, as well as learn how to use the System Trace Instrument to monitor system calls and track down performance issues within the application.

Chapter 5, Working with the Location Services and the MapKit Frameworks, introduces a detailed guide for using the built-in location services to create applications that provide location information to the user. You will not only learn how to use the GPS hardware, but also how to display maps and layout information using Overlays.

Chapter 6, Storing Documents within the Cloud, introduces you to the benefits of using iCloud, and how to incorporate iCloud functionality into your applications to store and retrieve files, and its data through the use of the Storage APIs. This chapter will also give you some insight into how to go about handling file version conflicts when multiple copies of the same file are being updated on more than one iOS device.

Chapter 7, Working with the Different Multimedia Resources, focuses on teaching you to create applications that capture, reproduce, and manage multimedia content through the device's hardware. You will not only learn to use the camera to capture images and videos but also how to play back and record audio. We will also learn how to implement the different image filter effects and transition animations to produce a water ripple effect, as well as learning how to incorporate Airplay functionality into our application.

Chapter 8, Working with the CoreData and GameKit Frameworks, focuses on showing you how to use the Core Data framework to create a simple Books Library application, to directly interface with a SQLite database, to create and store book details. We will also look at how to incorporate Bluetooth functionality, so that you can send book details to another iOS device, and have this information received wirelessly and stored within the database at the other end.

Chapter 9, Creating a Social Networking App with the Facebook iOS SDK, shows you how to download the Facebook SDK and register your application with Facebook. It also shows you how to use the Facebook APIs to integrate Facebook functionality into your app, using the Single Sign On (SSO) feature. This provides users the ability to sign into your application using their Facebook identity, so that they can submit notification requests, or submit content to their wall. We will learn how to use the Open Graph API and Facebook Query Language (FQL) to pass SQL Query like syntax to retrieve information about the current user, and learn how to cleanly handle Facebook errors within our iOS applications.

Chapter 10, Packaging and Deploying Your Application, walks you through the required steps to deploy your finished application to devices, as well as showing you how to prepare and distribute it to the App Store. We will also take a look at how to create and obtain provisioning profiles for both development and distribution.

Appendix, Exploring the MultiTouch Interface, discusses how to create applications that are fully aware of their surrounding environment, through the device's sensors. You will learn to adjust the user interface according to device orientations and how to respond to accelerometer and gyroscope events. You will also learn about the built-in shake gesture, and how to go about responding to the shake motions.

What you need for this book

The minimum requirement for this book is an Intel-based Macintosh computer running Mac OS X Snow Leopard (10.6.*) or Lion (10.7.*). I would highly recommend upgrading to Lion or Mountain Lion, as there are many new features in Xcode that are available only to these two operating systems.

We will be using Xcode 4.6.2, which is the integrated development environment used for creating applications for iOS development. Almost all projects you will create with the help of this book will work on the iOS Simulator. However, some projects will require a device to work correctly. You can download the latest version of Xcode at the following link: http://developer.apple.com/xcode/

Who this book is for

If you ever wanted to build applications that interact with Facebook, iCloud, Core Location, and the Core Motion frameworks into your own applications then this book is for you. You should have a good knowledge and programming experience with Objective-C and have used Xcode 4 and iOS 5.

Conventions

In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text are shown as follows: "Whenever compiler directives are used in Objective-C, they are responsible for responding to and executing the associated snippets of code encapsulated within the #ifdef and #endif tags".

A block of code is set as follows:

- (IBAction)btnTapHere:(id)sender { 
   NSString *greeting = [NSString stringWithFormat:@"Welcome 
                To Xcode 4 Cookbook series %@ %@",txtFirstname.text, txtSurname.text]; 
    lblOutput.text = greeting; 
    lblOutput.font = [UIFont boldSystemFontOfSize:21]; 
    lblOutput.textColor = [UIColor blueColor]; 
}

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

//  SecondViewController.h
//  TwitterExample
//
//  Created by Steven F Daniel on 21/09/12.
//  Copyright (c) 2012 GenieSoft Studios. All rights reserved.

#import <UIKit/UIKit.h>

@interface SecondViewController : UIViewController<UIAlertViewDelegate>

@end

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: " To continue execution of your application, click on the Continue program execution button".

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to , and mention the book title via the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the erratasubmissionform link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.

Piracy

Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.

Questions

You can contact us at if you are having a problem with any aspect of the book, and we will do our best to address it.