iphone development overview

267

Click here to load reader

Upload: william-taysom

Post on 12-May-2015

5.440 views

Category:

Technology


0 download

DESCRIPTION

Summary of what you need to know to get started with iPhone development: your relationship with Apple, developer tools, the iPhone Platform, and Objective-C

TRANSCRIPT

Page 1: iPhone Development Overview

iPhone Application Development

William Taysom2009 April 22

Page 2: iPhone Development Overview

The iPhone.

Page 3: iPhone Development Overview

January 9, 2007

Introduced in 2007.

Page 4: iPhone Development Overview

30 Million Sold

30 Million Sold.

Page 5: iPhone Development Overview

An impessive device.

Page 6: iPhone Development Overview

• 480×320 display

• 163ppi (50% more than your MacBook)

• 8GB, 16GB, even 32GB of Storage

Large display, high resolution, gigabyes of storage, ...

Page 7: iPhone Development Overview

• Speaker

• Mic

• Headphone

...a speaker, mic, headphone, ...

Page 8: iPhone Development Overview

• Camera

• Wireless

• GPS

...camera, wireless, GPS, ...

Page 9: iPhone Development Overview

• Accelerometer

• Ambient Light Sensor

• Proximity Sensor

...accelerometer, light sensor, proximity sensor, ...

Page 10: iPhone Development Overview

• And it’s a Phone.

...and itʼs a phone.But thatʼs not why weʼre here.

Page 11: iPhone Development Overview

This is why weʼre here.25,000 Apps.

Page 12: iPhone Development Overview

1 billion downloads.

Page 13: iPhone Development Overview

You want some.

You want some.

Page 14: iPhone Development Overview

I will show you how.

I will show you how.

Page 15: iPhone Development Overview

iPhone application development has four aspects:• Your relationship with Apple,• the iPhone developer tools,• the iPhone Platform, and• the Objective-C programming language.

Page 16: iPhone Development Overview

iPhone application development has four aspects:• Your relationship with Apple,• the iPhone developer tools,• the iPhone Platform, and• the Objective-C programming language.

Page 17: iPhone Development Overview

iPhone application development has four aspects:• Your relationship with Apple,• the iPhone developer tools,• the iPhone Platform, and• the Objective-C programming language.

Page 18: iPhone Development Overview

iPhone application development has four aspects:• Your relationship with Apple,• the iPhone developer tools,• the iPhone Platform, and• the Objective-C programming language.

Page 19: iPhone Development Overview

iPhone application development has four aspects:• Your relationship with Apple,• the iPhone developer tools,• the iPhone Platform, and• the Objective-C programming language.

Page 20: iPhone Development Overview

Letʼs talk about your relationship with Apple.

Page 21: iPhone Development Overview

• Apple makes the device.

• Apple provides the tools.

• Apple approves your apps.

Apple makes the device.Apple provides the tools.Apple approves your apps.

Page 22: iPhone Development Overview

• You will have a relationship with Apple.

You will have a relationship with Apple.Your relationship is mediated by three web sites:

Page 23: iPhone Development Overview

iPhone Dev Center

...the iPhone Dev Center, ...

Page 24: iPhone Development Overview

iPhone Developer Program Portal

...the iPhone Developer Program Portal, ...

Page 25: iPhone Development Overview

iTunes Connect

...and iTunes Connect.

Page 26: iPhone Development Overview

This chart summarizes the iPhone development process from signing up with the Dev Center• to seeing your app on the AppStore.

Page 27: iPhone Development Overview

This chart summarizes the iPhone development process from signing up with the Dev Center• to seeing your app on the AppStore.

Page 28: iPhone Development Overview

Your journey begins...

Page 29: iPhone Development Overview

Your journey begins...

Page 30: iPhone Development Overview

...at the iPhone Dev Center.

Page 31: iPhone Development Overview

iPhone Dev Center

Letʼs check it out.

Page 32: iPhone Development Overview

This is where you download the SDK, ...

Page 33: iPhone Development Overview

This is where you download the SDK, ...

Page 34: iPhone Development Overview

...and is one place where you can read documention.

Page 35: iPhone Development Overview

With the SDK, you are ready to develop your app.In the mean time, ...

Page 36: iPhone Development Overview

...you should sign up for the iPhone Developer Program.

Page 37: iPhone Development Overview

From the iPhone Dev Cenver,• you learn more about the Developer Program.

Page 38: iPhone Development Overview

From the iPhone Dev Cenver,• you learn more about the Developer Program.

Page 39: iPhone Development Overview

“iPhone Developer Program: The fastest path from code to customer.”The Program isnʼt just the fastest path: itʼs the only path.To put your App on a device or on the store, you need to join the program.

Page 40: iPhone Development Overview

After signing up, you need to be approved.With the Standard program, you sign up as an individual or as a corporation.We signed up as a corporation. We needed to fax Apple a copy of our Articles of Incorporation.Then they called us for confirmation.Then we needed to call them again after they sent us the wrong form email.• In total, the process took us about a month.

Page 41: iPhone Development Overview

After signing up, you need to be approved.With the Standard program, you sign up as an individual or as a corporation.We signed up as a corporation. We needed to fax Apple a copy of our Articles of Incorporation.Then they called us for confirmation.Then we needed to call them again after they sent us the wrong form email.• In total, the process took us about a month.

Page 42: iPhone Development Overview

Once approved,• you visit the Program Portal.

Page 43: iPhone Development Overview

Once approved,• you visit the Program Portal.

Page 44: iPhone Development Overview

iPhone Developer Program Portal

The portal provides you with provisioning profiles.

Page 45: iPhone Development Overview

A provisioning profile allows you to sign apps.A signature gives you permission to test an app on a device or to prepare an app for distribution.

Page 46: iPhone Development Overview

iPhone Development Certificate

App ID

Unique Device ID

You need to collect three things in order to generate a provisioning profile:

Page 47: iPhone Development Overview

iPhone Development Certificate who

App ID

Unique Device ID

An iPhone Development Certificate tells who will use the profile.

Page 48: iPhone Development Overview

iPhone Development Certificate who

App ID what

Unique Device ID

An app ID identifies what app the person is working on.

Page 49: iPhone Development Overview

iPhone Development Certificate who

App ID what

Unique Device ID where

A unique device ID determines where the app will be used, which device or the store.

Page 50: iPhone Development Overview

It's a bit like the game Cleudo: who done it, where, and with what weapon.

Page 51: iPhone Development Overview

While youʼre preparing your app, ...

Page 52: iPhone Development Overview

While youʼre preparing your app, ...

Page 53: iPhone Development Overview

...you should visit iTunes Connect. iTunes Connect is...

Page 54: iPhone Development Overview

iTunes Connect

...your backdoor enterance into the iTunes Store.

Page 55: iPhone Development Overview

From iTunes Connect,• you fill out a paid applications contact so that you can sell your app on the store.You need to provide Apple with your bank and tax info.They need to verify it. The turnaround can be a few days or weeks.

Page 56: iPhone Development Overview

From iTunes Connect,• you fill out a paid applications contact so that you can sell your app on the store.You need to provide Apple with your bank and tax info.They need to verify it. The turnaround can be a few days or weeks.

Page 57: iPhone Development Overview

While youʼre waiting for your contract, you can upload your app and its accompanying artwork.

Page 58: iPhone Development Overview

At this point, you are waiting for your contract and for app approval.Though people have been stuck waiting,my first app was approved within 24 hours.Since then, Iʼve always received feedback within a few days.

Page 59: iPhone Development Overview

Okay,• back to the top.

Page 60: iPhone Development Overview

Okay,• back to the top.

Page 61: iPhone Development Overview

Start by signing up with iPhone Dev Center.Download the SDK. Work on your app.

Page 62: iPhone Development Overview

Start by signing up with iPhone Dev Center.Download the SDK. Work on your app.

Page 63: iPhone Development Overview

Sign up for the iPhone Developer program.

Page 64: iPhone Development Overview

Sign up for the iPhone Developer program.

Page 65: iPhone Development Overview

Go through the approval process.

Page 66: iPhone Development Overview

Go through the approval process.

Page 67: iPhone Development Overview

Gather info for the program portal.• Fill out the paid applications contract from iTunes Connect.Submit your app.• Wait for approval.

Page 68: iPhone Development Overview

Gather info for the program portal.• Fill out the paid applications contract from iTunes Connect.Submit your app.• Wait for approval.

Page 69: iPhone Development Overview

Gather info for the program portal.• Fill out the paid applications contract from iTunes Connect.Submit your app.• Wait for approval.

Page 70: iPhone Development Overview

Gather info for the program portal.• Fill out the paid applications contract from iTunes Connect.Submit your app.• Wait for approval.

Page 71: iPhone Development Overview

Enjoy the fruits of your labor.

Page 72: iPhone Development Overview

That is your relationship with Apple.

Page 73: iPhone Development Overview

Letʼs talk about tools.The iPhone SDK includes everything you need for iPhone (and Mac) development.

Page 74: iPhone Development Overview

We will use four tools:• Xcode• The iPhone Simulator• Interface Builder• Instruments

Page 75: iPhone Development Overview

We will use four tools:• Xcode• The iPhone Simulator• Interface Builder• Instruments

Page 76: iPhone Development Overview

We will use four tools:• Xcode• The iPhone Simulator• Interface Builder• Instruments

Page 77: iPhone Development Overview

We will use four tools:• Xcode• The iPhone Simulator• Interface Builder• Instruments

Page 78: iPhone Development Overview

We will use four tools:• Xcode• The iPhone Simulator• Interface Builder• Instruments

Page 79: iPhone Development Overview

Xcode is Apple's integrated development environment. We will spend most of our time in it.

Page 80: iPhone Development Overview

Xcode is a front end for command-line utilities:• compiling with gcc,• linking with ld,• debugging with gdb, and• version control (also called source code management): svn, cvs, or Perforce.

Page 81: iPhone Development Overview

• compling ↣ gcc

Xcode is a front end for command-line utilities:• compiling with gcc,• linking with ld,• debugging with gdb, and• version control (also called source code management): svn, cvs, or Perforce.

Page 82: iPhone Development Overview

• compling ↣ gcc

• linking ↣ ld

Xcode is a front end for command-line utilities:• compiling with gcc,• linking with ld,• debugging with gdb, and• version control (also called source code management): svn, cvs, or Perforce.

Page 83: iPhone Development Overview

• compling ↣ gcc

• linking ↣ ld

• debugging ↣ gdb

Xcode is a front end for command-line utilities:• compiling with gcc,• linking with ld,• debugging with gdb, and• version control (also called source code management): svn, cvs, or Perforce.

Page 84: iPhone Development Overview

• compling ↣ gcc

• linking ↣ ld

• debugging ↣ gdb

• SCM ↣ svn, cvs, Perforce

Xcode is a front end for command-line utilities:• compiling with gcc,• linking with ld,• debugging with gdb, and• version control (also called source code management): svn, cvs, or Perforce.

Page 85: iPhone Development Overview

Window Types

Xcode has many types of windows:

Page 86: iPhone Development Overview

Editor

...the editor, ...

Page 87: iPhone Development Overview

Documentation

...documentation, ..

.

Page 88: iPhone Development Overview

Build

...build, ..

.

Page 89: iPhone Development Overview

Console

...debugging console, ...

Page 90: iPhone Development Overview

Debugger

...debugger, ..

.

Page 91: iPhone Development Overview

Project

...the project window (Xcodeʼs main window), ...

Page 92: iPhone Development Overview

Info

...info windows, ...

Page 93: iPhone Development Overview

Organizer

...an organizer for your iPhone, ...

Page 94: iPhone Development Overview

SCM

...and source code managment.

Page 95: iPhone Development Overview

We will see all of these windows before weʼre done with Xcode.

Page 96: iPhone Development Overview

The iPhone Simulator is great for everyday testing and debugging.

Page 97: iPhone Development Overview

Looks just like the real thing in portrait...

Page 98: iPhone Development Overview

...and in landscape.

Page 99: iPhone Development Overview

Thatʼs the gist of the simulator.

Page 100: iPhone Development Overview

Interface Builder helps you layout the views for your app.

Page 101: iPhone Development Overview

These are your primary IB windows.

Page 102: iPhone Development Overview

Main Window

The main window shows all of the objects in your interface builder document.

Page 103: iPhone Development Overview

View Window

The view window is where you layout the subviews of a view.

Page 104: iPhone Development Overview

Attribute Inspector

The inspector allows you to edit properties of your objects.Here we see the visual attributes of a slider.

Page 105: iPhone Development Overview

Connections Inspector

And here we see connections between the slider and other objects.

Page 106: iPhone Development Overview

Interface Builder can remove the guesswork of in-code layout.But be warned. IB can trip you up due to limitations and bugs.

Page 107: iPhone Development Overview

Instruments is used for profiling and, ...

Page 108: iPhone Development Overview

...most importantly, itʼs used in checking for memory leaks.

Page 109: iPhone Development Overview

We will have some good runs with Instruments over the next few days.

Page 110: iPhone Development Overview

These are tools which weʼll be using.However, the SDK offers many more.

Page 111: iPhone Development Overview

We have graphics tools, ...

Page 112: iPhone Development Overview

...performance tools, ...

Page 113: iPhone Development Overview

...utilities, ..

.

Page 114: iPhone Development Overview

...and Dashcode.Before native iPhone apps were an option, Dashcode was created to make iPhone specific Web Applications.

Page 115: iPhone Development Overview

Hereʼs Dashcode.If it turns out that native development wonʼt work well for youor if you have stronger experience with web development, ...

Page 116: iPhone Development Overview

...I recommend that you look into Dashcode.

Page 117: iPhone Development Overview

Xcode, iPhone Simulator, Interface Builder, Instruments...

Page 118: iPhone Development Overview

...these are the tools that weʼll be using.

Page 119: iPhone Development Overview

Turn your attention to the iPhone platform.

Page 120: iPhone Development Overview

The iPhone OS provides several layers of services.Services on higher layers abstract away details from services on lower layers.Services on lower layers provide more flexibility as well as more inconvenience and tedium.Letʼs start at the bottom.

Page 121: iPhone Development Overview

Just like Mac OS X, the iPhone is built on the Mach UNIX kernel.Core OS exposes common UNIX libraries.

Page 122: iPhone Development Overview

Core OS

POSIX threads for in shared state multithreaded concurrency.• BSD sockets for low level TCP and UDP networking.• Standard C libraries including stdio, stdlib, and the rest.

Page 123: iPhone Development Overview

• POSIX Threads ↣ Concurrency

Core OS

POSIX threads for in shared state multithreaded concurrency.• BSD sockets for low level TCP and UDP networking.• Standard C libraries including stdio, stdlib, and the rest.

Page 124: iPhone Development Overview

• POSIX Threads ↣ Concurrency

• BSD Sockets ↣ TCP & UDP Networking

Core OS

POSIX threads for in shared state multithreaded concurrency.• BSD sockets for low level TCP and UDP networking.• Standard C libraries including stdio, stdlib, and the rest.

Page 125: iPhone Development Overview

• POSIX Threads ↣ Concurrency

• BSD Sockets ↣ TCP & UDP Networking

• <stdio.h> <stdlib.h> ...the rest

Core OS

POSIX threads for in shared state multithreaded concurrency.• BSD sockets for low level TCP and UDP networking.• Standard C libraries including stdio, stdlib, and the rest.

Page 126: iPhone Development Overview

Core services include OS X specific libraries as well as popular, relatively new C libraries.

Page 127: iPhone Development Overview

Core services include OS X specific libraries as well as popular, relatively new C libraries.

Page 128: iPhone Development Overview

Core Services

Core foundation is the plain C library which mirrors Objective-C Foundation classes.• Core Location enables your iPhone to determine where it is.• SQLite is for lightweight SQL databases.• libxml2 is for heavy duty XML processing.

Page 129: iPhone Development Overview

• Core Foundation ↣ Foundation Mirror

Core Services

Core foundation is the plain C library which mirrors Objective-C Foundation classes.• Core Location enables your iPhone to determine where it is.• SQLite is for lightweight SQL databases.• libxml2 is for heavy duty XML processing.

Page 130: iPhone Development Overview

• Core Foundation ↣ Foundation Mirror

• Core Location ↣ GPS

Core Services

Core foundation is the plain C library which mirrors Objective-C Foundation classes.• Core Location enables your iPhone to determine where it is.• SQLite is for lightweight SQL databases.• libxml2 is for heavy duty XML processing.

Page 131: iPhone Development Overview

• Core Foundation ↣ Foundation Mirror

• Core Location ↣ GPS

• SQLite ↣ SQL Database

Core Services

Core foundation is the plain C library which mirrors Objective-C Foundation classes.• Core Location enables your iPhone to determine where it is.• SQLite is for lightweight SQL databases.• libxml2 is for heavy duty XML processing.

Page 132: iPhone Development Overview

• Core Foundation ↣ Foundation Mirror

• Core Location ↣ GPS

• SQLite ↣ SQL Database

• libxml2 ↣ XML Processing

Core Services

Core foundation is the plain C library which mirrors Objective-C Foundation classes.• Core Location enables your iPhone to determine where it is.• SQLite is for lightweight SQL databases.• libxml2 is for heavy duty XML processing.

Page 133: iPhone Development Overview

The media layer supports 2D and 3D graphics, audio, and video.

Page 134: iPhone Development Overview

The media layer supports 2D and 3D graphics, audio, and video.

Page 135: iPhone Development Overview

Media

For audio, we have Core Audio and OpenAL.• OpenGL ES is geared toward 3D graphics.• Quartz, also called Core Graphics, provides 2D graphics support.• Core Animation provides all those animated effects we see on the iPhone and the Mac• including this presentation. •

Page 136: iPhone Development Overview

• Core Audio & OpenAL ↣ Audio

Media

For audio, we have Core Audio and OpenAL.• OpenGL ES is geared toward 3D graphics.• Quartz, also called Core Graphics, provides 2D graphics support.• Core Animation provides all those animated effects we see on the iPhone and the Mac• including this presentation. •

Page 137: iPhone Development Overview

• Core Audio & OpenAL ↣ Audio

• OpenGL ES ↣ 3D Graphics

Media

For audio, we have Core Audio and OpenAL.• OpenGL ES is geared toward 3D graphics.• Quartz, also called Core Graphics, provides 2D graphics support.• Core Animation provides all those animated effects we see on the iPhone and the Mac• including this presentation. •

Page 138: iPhone Development Overview

• Core Audio & OpenAL ↣ Audio

• OpenGL ES ↣ 3D Graphics

• Quartz (Core Graphics) ↣ 2D Graphics

Media

For audio, we have Core Audio and OpenAL.• OpenGL ES is geared toward 3D graphics.• Quartz, also called Core Graphics, provides 2D graphics support.• Core Animation provides all those animated effects we see on the iPhone and the Mac• including this presentation. •

Page 139: iPhone Development Overview

• Core Audio & OpenAL ↣ Audio

• OpenGL ES ↣ 3D Graphics

• Quartz (Core Graphics) ↣ 2D Graphics

• Core Animation ↣ Animated Effects

Media

For audio, we have Core Audio and OpenAL.• OpenGL ES is geared toward 3D graphics.• Quartz, also called Core Graphics, provides 2D graphics support.• Core Animation provides all those animated effects we see on the iPhone and the Mac• including this presentation. •

Page 140: iPhone Development Overview

For audio, we have Core Audio and OpenAL.• OpenGL ES is geared toward 3D graphics.• Quartz, also called Core Graphics, provides 2D graphics support.• Core Animation provides all those animated effects we see on the iPhone and the Mac• including this presentation. •

Page 141: iPhone Development Overview

Cocoa Touch contains the Objective-C frameworks you use to build your application.

Page 142: iPhone Development Overview

Cocoa Touch contains the Objective-C frameworks you use to build your application.

Page 143: iPhone Development Overview

Foundation

Foundation is the essential Objective-C framework. Foundation contains:• NSObject, the root of the Objective-C class hierarchy,• Data type wrappers,• Collections,• Local filesystem access,• HTTP requests, and much more.

Page 144: iPhone Development Overview

• NSObject

Foundation

Foundation is the essential Objective-C framework. Foundation contains:• NSObject, the root of the Objective-C class hierarchy,• Data type wrappers,• Collections,• Local filesystem access,• HTTP requests, and much more.

Page 145: iPhone Development Overview

• NSObject

• NSString, NSNumber, NSNull

Foundation

Foundation is the essential Objective-C framework. Foundation contains:• NSObject, the root of the Objective-C class hierarchy,• Data type wrappers,• Collections,• Local filesystem access,• HTTP requests, and much more.

Page 146: iPhone Development Overview

• NSObject

• NSString, NSNumber, NSNull

• NSArray, NSDictionary, NSSet

Foundation

Foundation is the essential Objective-C framework. Foundation contains:• NSObject, the root of the Objective-C class hierarchy,• Data type wrappers,• Collections,• Local filesystem access,• HTTP requests, and much more.

Page 147: iPhone Development Overview

• NSObject

• NSString, NSNumber, NSNull

• NSArray, NSDictionary, NSSet

• NSFileManager, NSFileHandle

Foundation

Foundation is the essential Objective-C framework. Foundation contains:• NSObject, the root of the Objective-C class hierarchy,• Data type wrappers,• Collections,• Local filesystem access,• HTTP requests, and much more.

Page 148: iPhone Development Overview

• NSObject

• NSString, NSNumber, NSNull

• NSArray, NSDictionary, NSSet

• NSFileManager, NSFileHandle

• NSURL, NSURLRequest, NSURLResponse

Foundation

Foundation is the essential Objective-C framework. Foundation contains:• NSObject, the root of the Objective-C class hierarchy,• Data type wrappers,• Collections,• Local filesystem access,• HTTP requests, and much more.

Page 149: iPhone Development Overview

CocoaAsyncSocket

For TCP and UDP networking, nothing beats CocoaAsyncSocket.Though not part of the iPhone SDK, CocoaAsyncSocket is such an valuable networking librarythat I can't help but mention it.

Page 150: iPhone Development Overview

UIKit

UIKit contains all the standard views and controllers which make up your application.• From the time the user taps the application icon to the moment when application execution terminates, UIKit is in charge.

Page 151: iPhone Development Overview

UIKit

UIKit contains all the standard views and controllers which make up your application.• From the time the user taps the application icon to the moment when application execution terminates, UIKit is in charge.

Page 152: iPhone Development Overview

UIKit handles the main event loop and calls you when it expects a response.How does it work?

Page 153: iPhone Development Overview

How does the touch screen interface relate to the source code implementation?

Page 154: iPhone Development Overview

Consider the clock application.

Page 155: iPhone Development Overview

What parts make up the clock?

Page 156: iPhone Development Overview

UIKit uses windows and views to fill the screen.

Page 157: iPhone Development Overview

The OS has a window with the status bar on the top.The application window fills the rest of the screen below it.

Page 158: iPhone Development Overview

The window contains the main view for the application.

Page 159: iPhone Development Overview

The view has a tab bar at the bottomand another view for the World Clock.

Page 160: iPhone Development Overview

The World clock has a navigation bar on top.A table view fills the rest.

Page 161: iPhone Development Overview

This table has one cell.

Page 162: iPhone Development Overview

The cell contains four labels and a special clock face.This is how the Clock application is divided into views.Each view is a UIView subclass.

Page 163: iPhone Development Overview

Here, the views are relabed with class names.The status bar is associated with the UIApplication class.The window is a UIWindow.The tab bar is a UITabBar, etc.The cell is a UITableViewCell.The labels are UILabels,and the clock face is some custom UIView.

Page 164: iPhone Development Overview

A viewʼs responsibility is to represent some piece of information or to layout some subviews.UIKit uses controller classes to update and to keep track of views.

Page 165: iPhone Development Overview

A UIApplicationDelegatecreates the main window,creates the main view controller,and places the controllerʼs view in the window.

Page 166: iPhone Development Overview

All this happens in the applicationDidFinishLaunching: method of the UIApplicationDelegate.

Page 167: iPhone Development Overview

UIKit has specific controllers for managing certain kinds of views.

Page 168: iPhone Development Overview

A UITabBarController mangages a tab bar.It responds to touches on the bar by displaying the corresponding tab.Each tab has a controller.

Page 169: iPhone Development Overview

This diagram shows a UITabBarController with several view controllers.The title of a controller provides the label for its tab bar button.The controllerʼs tab bar item tells the tab bar controller which image to show on the tab bar button.The selected controllerʼs view fills the space above the tab bar.

Page 170: iPhone Development Overview

In our case, the view is associated with the controller for the World Clock.

Page 171: iPhone Development Overview

Since the World Clock has a navigation bar on top, its controller is a UINavigationController.A navigation controller manages a stack of controllers whose views are pushed in from the right.In the clock, the stack only contains one controller.

Page 172: iPhone Development Overview

So letʼs look at the address book for a minute.When you touch a Johnʼs name, ...

Page 173: iPhone Development Overview

...his info slides right in.The upper left corner provides a back button.

Page 174: iPhone Development Overview

We have three controllers on the UINavigationContoller stack.

Page 175: iPhone Development Overview

At the top of the stack, in the bottom right corner of the diagram, we see Johnʼs info.His info is pushed on top up of the All Contacts controller,which, in turn, is pushed on top of the Groups controller.

Page 176: iPhone Development Overview

The title of the top controller is used as the title of the navigation bar.The view fills the space under the navigation bar.The navigation item populates the navigation bar with other informationincluding custom bar buttons.

Page 177: iPhone Development Overview

The title of the top controller is used as the title of the navigation bar.The view fills the space under the navigation bar.The navigation item populates the navigation bar with other informationincluding custom bar buttons.

Page 178: iPhone Development Overview

Letʼs return to the Clock.

Page 179: iPhone Development Overview

Notice that the UINavigationController is contained in the UITabBarController.

Page 180: iPhone Development Overview

Whenever you have a tab bar controller and a navigation controller,the tab bar should be on the outside and the navigation controller should be on the inside.Iʼve tried it the other way. It just doesnʼt work: the controllers get very confused.

Page 181: iPhone Development Overview

What controller manages the UITableView?

Page 182: iPhone Development Overview

Why itʼs a UITableViewController.The UITableViewController serves as the data source for the table view.It tells the table how many rows there are and what cell to put in each visible row.

Page 183: iPhone Development Overview

How does the table view controller know what to put in the table?How does it remember the list of clocks?The controller asks the model.I canʼt be sure how Apple wrote the Clock app, but we can imagine what the model is like.Since the clock only needs to keep track of a little data,they shouldnʼt bother with SQLite databases or external property list files.

Page 184: iPhone Development Overview

Instead, they probably store all the data in the user defaults database.What data specifically?

Page 185: iPhone Development Overview

Again, I canʼt be sure, but I guess they use a time zone object.

Page 186: iPhone Development Overview

They need to keep an array of time zones: one for each clock.Since you can add and remove clocks, the array might be mutable.

Page 187: iPhone Development Overview

For each tab in the app, they need to keep some data.So I suppose they use an array for that.

Page 188: iPhone Development Overview

Finally, they could use an index to remember which of the tabs is selected.

Page 189: iPhone Development Overview

Step back.• We have our model,• our view,• and our controller.• Combine them...

Page 190: iPhone Development Overview

Model

Step back.• We have our model,• our view,• and our controller.• Combine them...

Page 191: iPhone Development Overview

ModelView

Step back.• We have our model,• our view,• and our controller.• Combine them...

Page 192: iPhone Development Overview

ModelView Controller

Step back.• We have our model,• our view,• and our controller.• Combine them...

Page 193: iPhone Development Overview

Step back.• We have our model,• our view,• and our controller.• Combine them...

Page 194: iPhone Development Overview

...to get our app.

Page 195: iPhone Development Overview

Weʼll be making three apps over the next few days.

Page 196: iPhone Development Overview

Before starting, letʼs finish our overview.

Page 197: iPhone Development Overview

The Cocoa Touch layer contains the primary APIs youʼll use in making apps.

Page 198: iPhone Development Overview

Turn to other layers as needed.Truly, ...

Page 199: iPhone Development Overview

...the iPhone is an impressive platform.

Page 200: iPhone Development Overview

Objective-C is the language you use to speak to the platform.

Page 201: iPhone Development Overview

History

History time.

Page 202: iPhone Development Overview

1981: Brad Cox

Objective-C was developed by Brad Cox in the early eighties.

Page 203: iPhone Development Overview

1988: NeXT

In 1988 NeXT Inc. licensed Objective-C...

Page 204: iPhone Development Overview

NeXTstep

...for their NeXTstep operating system.

Page 205: iPhone Development Overview

1996: Jobs Returns

In 1996 Steve Jobs and NeXT joined Apple.

Page 206: iPhone Development Overview

NeXTstep

NeXTstep became...

Page 207: iPhone Development Overview

Mac OS X

...Mac OS X.Letʼs see that again.

Page 208: iPhone Development Overview

NeXTstep

NeXTstep became...

Page 209: iPhone Development Overview

Mac OS X

...Mac OS X.One more time.

Page 210: iPhone Development Overview

NeXTstep became...

Page 211: iPhone Development Overview

...Mac OS X.

Page 212: iPhone Development Overview

Objective-C

Objective-C came along for the ride.Since iPhone OS is a version of Mac OS X, the iPhone's programming language is Objective-C.

Page 213: iPhone Development Overview

Design

What is Objective-C like?

Page 214: iPhone Development Overview

Objective-C brings some Object-Oriented features from Smalltalk into C.

Page 215: iPhone Development Overview

Runtime

Objective-C uses a lightweight runtime library in contrast to the virtual machines of Java and .Net.• Objects are pointers to C structures.• Methods are C functions.• Classes are constructed at runtime.

Page 216: iPhone Development Overview

• Object ↣ struct objc_object *

Runtime

Objective-C uses a lightweight runtime library in contrast to the virtual machines of Java and .Net.• Objects are pointers to C structures.• Methods are C functions.• Classes are constructed at runtime.

Page 217: iPhone Development Overview

• Object ↣ struct objc_object *

• Method ↣ C Function

Runtime

Objective-C uses a lightweight runtime library in contrast to the virtual machines of Java and .Net.• Objects are pointers to C structures.• Methods are C functions.• Classes are constructed at runtime.

Page 218: iPhone Development Overview

• Object ↣ struct objc_object *

• Method ↣ C Function

• Class ↣ Runtime Constructed

Runtime

Objective-C uses a lightweight runtime library in contrast to the virtual machines of Java and .Net.• Objects are pointers to C structures.• Methods are C functions.• Classes are constructed at runtime.

Page 219: iPhone Development Overview

Syntax

Objective-C's syntax is the same as C syntax with a few additions.

Page 220: iPhone Development Overview

Directives

Directives are prefixed by the at-sign.• These are the ones I type most often.• These, though common, are usually typed by Xcode when you make a new class.• Exceptions arenʼt often caught in Objective-C. They usually represent program errors.• I rarely use any of the directives in this last group.

Page 221: iPhone Development Overview

Directives

• @"string literal" @property @synthesize @selector()

Directives are prefixed by the at-sign.• These are the ones I type most often.• These, though common, are usually typed by Xcode when you make a new class.• Exceptions arenʼt often caught in Objective-C. They usually represent program errors.• I rarely use any of the directives in this last group.

Page 222: iPhone Development Overview

Directives

• @"string literal" @property @synthesize @selector()

• @interface @implementation @protocol @class @end

Directives are prefixed by the at-sign.• These are the ones I type most often.• These, though common, are usually typed by Xcode when you make a new class.• Exceptions arenʼt often caught in Objective-C. They usually represent program errors.• I rarely use any of the directives in this last group.

Page 223: iPhone Development Overview

Directives

• @"string literal" @property @synthesize @selector()

• @interface @implementation @protocol @class @end

• @dynamic @try @throw @catch() @finally

Directives are prefixed by the at-sign.• These are the ones I type most often.• These, though common, are usually typed by Xcode when you make a new class.• Exceptions arenʼt often caught in Objective-C. They usually represent program errors.• I rarely use any of the directives in this last group.

Page 224: iPhone Development Overview

Directives

• @"string literal" @property @synthesize @selector()

• @interface @implementation @protocol @class @end

• @dynamic @try @throw @catch() @finally

• @protocol() @private @projected @public @synchronized() @encode()

Directives are prefixed by the at-sign.• These are the ones I type most often.• These, though common, are usually typed by Xcode when you make a new class.• Exceptions arenʼt often caught in Objective-C. They usually represent program errors.• I rarely use any of the directives in this last group.

Page 225: iPhone Development Overview

Messages

Method calls, also known as messages, use square brackets.• Here the receiver is a variable named “string” and the method name, or selector, is “integerValue”.• Arguments come after a colon.• For multiple arguments, the method name is broken into parts: one for each argument.The selector here is “stringByReplacingOccurrencesOfString:withString:”.In Objective-C, they like descriptive method names.• A method can take a variable number of comma-seperated arguments after its last colon.

Page 226: iPhone Development Overview

Messages

• [string integerValue]

Method calls, also known as messages, use square brackets.• Here the receiver is a variable named “string” and the method name, or selector, is “integerValue”.• Arguments come after a colon.• For multiple arguments, the method name is broken into parts: one for each argument.The selector here is “stringByReplacingOccurrencesOfString:withString:”.In Objective-C, they like descriptive method names.• A method can take a variable number of comma-seperated arguments after its last colon.

Page 227: iPhone Development Overview

Messages

• [string integerValue]

• [string isEqualToString:anotherString]

Method calls, also known as messages, use square brackets.• Here the receiver is a variable named “string” and the method name, or selector, is “integerValue”.• Arguments come after a colon.• For multiple arguments, the method name is broken into parts: one for each argument.The selector here is “stringByReplacingOccurrencesOfString:withString:”.In Objective-C, they like descriptive method names.• A method can take a variable number of comma-seperated arguments after its last colon.

Page 228: iPhone Development Overview

Messages

• [string integerValue]

• [string isEqualToString:anotherString]

• [string stringByReplacingOccurrencesOfString:oneString

withString:anotherString]

Method calls, also known as messages, use square brackets.• Here the receiver is a variable named “string” and the method name, or selector, is “integerValue”.• Arguments come after a colon.• For multiple arguments, the method name is broken into parts: one for each argument.The selector here is “stringByReplacingOccurrencesOfString:withString:”.In Objective-C, they like descriptive method names.• A method can take a variable number of comma-seperated arguments after its last colon.

Page 229: iPhone Development Overview

Messages

• [string integerValue]

• [string isEqualToString:anotherString]

• [string stringByReplacingOccurrencesOfString:oneString

withString:anotherString]

• [NSString stringWithFormat:@"%d %@", number, string]

Method calls, also known as messages, use square brackets.• Here the receiver is a variable named “string” and the method name, or selector, is “integerValue”.• Arguments come after a colon.• For multiple arguments, the method name is broken into parts: one for each argument.The selector here is “stringByReplacingOccurrencesOfString:withString:”.In Objective-C, they like descriptive method names.• A method can take a variable number of comma-seperated arguments after its last colon.

Page 230: iPhone Development Overview

Method Declarations

Method declarations are similar to message sends.• A minus-sign indicates an instance method.A plus sign would indicate a class method. The return type is placed in parenthesis.• The type of a parameter is wrapped in parenthesis after the colon and before the parameter name.• As with messges, the selector is split when there are multiple parameters.• Hereʼs a class method. The comma and ellipses after the last parameter indicate that the method accepts a variable number of arguments.

Page 231: iPhone Development Overview

Method Declarations

• - (NSInteger)integerValue;

Method declarations are similar to message sends.• A minus-sign indicates an instance method.A plus sign would indicate a class method. The return type is placed in parenthesis.• The type of a parameter is wrapped in parenthesis after the colon and before the parameter name.• As with messges, the selector is split when there are multiple parameters.• Hereʼs a class method. The comma and ellipses after the last parameter indicate that the method accepts a variable number of arguments.

Page 232: iPhone Development Overview

Method Declarations

• - (NSInteger)integerValue;

• - (BOOL)isEqualToString:(NSString *)aString;

Method declarations are similar to message sends.• A minus-sign indicates an instance method.A plus sign would indicate a class method. The return type is placed in parenthesis.• The type of a parameter is wrapped in parenthesis after the colon and before the parameter name.• As with messges, the selector is split when there are multiple parameters.• Hereʼs a class method. The comma and ellipses after the last parameter indicate that the method accepts a variable number of arguments.

Page 233: iPhone Development Overview

Method Declarations

• - (NSInteger)integerValue;

• - (BOOL)isEqualToString:(NSString *)aString;

• - (NSString *)stringByReplacingOccurrencesOfString:(NSString *)target withString:(NSString *)replacement;

Method declarations are similar to message sends.• A minus-sign indicates an instance method.A plus sign would indicate a class method. The return type is placed in parenthesis.• The type of a parameter is wrapped in parenthesis after the colon and before the parameter name.• As with messges, the selector is split when there are multiple parameters.• Hereʼs a class method. The comma and ellipses after the last parameter indicate that the method accepts a variable number of arguments.

Page 234: iPhone Development Overview

Method Declarations

• - (NSInteger)integerValue;

• - (BOOL)isEqualToString:(NSString *)aString;

• - (NSString *)stringByReplacingOccurrencesOfString:(NSString *)target withString:(NSString *)replacement;

• + (id)stringWithFormat:(NSString *)format, ...;

Method declarations are similar to message sends.• A minus-sign indicates an instance method.A plus sign would indicate a class method. The return type is placed in parenthesis.• The type of a parameter is wrapped in parenthesis after the colon and before the parameter name.• As with messges, the selector is split when there are multiple parameters.• Hereʼs a class method. The comma and ellipses after the last parameter indicate that the method accepts a variable number of arguments.

Page 235: iPhone Development Overview

Dot Syntax

• [label text]

• [label setText:string]

Historically, this is how you would get and set a propery in Objective-C.• But that isnʼt the way itʼs usually done on the iPhone.

Page 236: iPhone Development Overview

Dot Syntax

Historically, this is how you would get and set a propery in Objective-C.• But that isnʼt the way itʼs usually done on the iPhone.

Page 237: iPhone Development Overview

Dot Syntax

Instead you use a dot for getters and setters. The meaning is the same.The compiled code is the same. Only the notation differs.

Page 238: iPhone Development Overview

Dot Syntax

• label.text

• label.text = string

Instead you use a dot for getters and setters. The meaning is the same.The compiled code is the same. Only the notation differs.

Page 239: iPhone Development Overview

Fast Enumeration

for (NSString *name in names) {

...

}

Last but not least, Objective-C has a special for loop to iterate across collections.

Page 240: iPhone Development Overview

Thatʼs Objective-C in a too-small nutshell.Your printed materials include a concise reference to Objective-C.The materials also include a reference to C and the C Preprocessor.

Page 241: iPhone Development Overview

To summarize:• Your relationship to Apple defines the process of iPhone development.• The SDK provides you with the tools.• The iPhone platform provides you with capabilities.• Objective-C provides you with the language.• These four aspects cover everything you need in order to develop on the iPhone and get those...

Page 242: iPhone Development Overview

To summarize:• Your relationship to Apple defines the process of iPhone development.• The SDK provides you with the tools.• The iPhone platform provides you with capabilities.• Objective-C provides you with the language.• These four aspects cover everything you need in order to develop on the iPhone and get those...

Page 243: iPhone Development Overview

To summarize:• Your relationship to Apple defines the process of iPhone development.• The SDK provides you with the tools.• The iPhone platform provides you with capabilities.• Objective-C provides you with the language.• These four aspects cover everything you need in order to develop on the iPhone and get those...

Page 244: iPhone Development Overview

To summarize:• Your relationship to Apple defines the process of iPhone development.• The SDK provides you with the tools.• The iPhone platform provides you with capabilities.• Objective-C provides you with the language.• These four aspects cover everything you need in order to develop on the iPhone and get those...

Page 245: iPhone Development Overview

To summarize:• Your relationship to Apple defines the process of iPhone development.• The SDK provides you with the tools.• The iPhone platform provides you with capabilities.• Objective-C provides you with the language.• These four aspects cover everything you need in order to develop on the iPhone and get those...

Page 246: iPhone Development Overview

To summarize:• Your relationship to Apple defines the process of iPhone development.• The SDK provides you with the tools.• The iPhone platform provides you with capabilities.• Objective-C provides you with the language.• These four aspects cover everything you need in order to develop on the iPhone and get those...

Page 247: iPhone Development Overview

...downloads.

Page 248: iPhone Development Overview

The rest of the course is a tutorial in which weʼll build three apps.

Page 249: iPhone Development Overview

Temp

We start with a temperature converter.• Weʼll learn all about Interface Builder,• views and controls,• how to use text fields,• alert windows,• landscape autorotation,• and weʼll localize the app.

Page 250: iPhone Development Overview

Temp

• Interface Builder

We start with a temperature converter.• Weʼll learn all about Interface Builder,• views and controls,• how to use text fields,• alert windows,• landscape autorotation,• and weʼll localize the app.

Page 251: iPhone Development Overview

Temp

• Interface Builder

• Views & Controls

We start with a temperature converter.• Weʼll learn all about Interface Builder,• views and controls,• how to use text fields,• alert windows,• landscape autorotation,• and weʼll localize the app.

Page 252: iPhone Development Overview

Temp

• Interface Builder

• Views & Controls

• Text Fields

We start with a temperature converter.• Weʼll learn all about Interface Builder,• views and controls,• how to use text fields,• alert windows,• landscape autorotation,• and weʼll localize the app.

Page 253: iPhone Development Overview

Temp

• Interface Builder

• Views & Controls

• Text Fields

• Alerts

We start with a temperature converter.• Weʼll learn all about Interface Builder,• views and controls,• how to use text fields,• alert windows,• landscape autorotation,• and weʼll localize the app.

Page 254: iPhone Development Overview

Temp

• Interface Builder

• Views & Controls

• Text Fields

• Alerts

• Autorotation

We start with a temperature converter.• Weʼll learn all about Interface Builder,• views and controls,• how to use text fields,• alert windows,• landscape autorotation,• and weʼll localize the app.

Page 255: iPhone Development Overview

Temp

• Interface Builder

• Views & Controls

• Text Fields

• Alerts

• Autorotation

• Localization

We start with a temperature converter.• Weʼll learn all about Interface Builder,• views and controls,• how to use text fields,• alert windows,• landscape autorotation,• and weʼll localize the app.

Page 256: iPhone Development Overview

The Elements

Our big example is a viewer for the atomic elements sorted in different ways.• Weʼll learn all about table views,• plists,• view controllers,• table view cells,• web views,• animation, and a whole lot more.

Page 257: iPhone Development Overview

The Elements

• Table Views

Our big example is a viewer for the atomic elements sorted in different ways.• Weʼll learn all about table views,• plists,• view controllers,• table view cells,• web views,• animation, and a whole lot more.

Page 258: iPhone Development Overview

The Elements

• Table Views

• Plists

Our big example is a viewer for the atomic elements sorted in different ways.• Weʼll learn all about table views,• plists,• view controllers,• table view cells,• web views,• animation, and a whole lot more.

Page 259: iPhone Development Overview

The Elements

• Table Views

• Plists

• View Controllers

Our big example is a viewer for the atomic elements sorted in different ways.• Weʼll learn all about table views,• plists,• view controllers,• table view cells,• web views,• animation, and a whole lot more.

Page 260: iPhone Development Overview

The Elements

• Table Views

• Plists

• View Controllers

• Table View Cells

Our big example is a viewer for the atomic elements sorted in different ways.• Weʼll learn all about table views,• plists,• view controllers,• table view cells,• web views,• animation, and a whole lot more.

Page 261: iPhone Development Overview

The Elements

• Table Views

• Plists

• View Controllers

• Table View Cells

• Web Views

Our big example is a viewer for the atomic elements sorted in different ways.• Weʼll learn all about table views,• plists,• view controllers,• table view cells,• web views,• animation, and a whole lot more.

Page 262: iPhone Development Overview

The Elements

• Table Views

• Plists

• View Controllers

• Table View Cells

• Web Views

• Animation

Our big example is a viewer for the atomic elements sorted in different ways.• Weʼll learn all about table views,• plists,• view controllers,• table view cells,• web views,• animation, and a whole lot more.

Page 263: iPhone Development Overview

GLGravity

As a final treat, weʼll play with• OpenGL ES• and the iPhoneʼs accelerometer.

Page 264: iPhone Development Overview

GLGravity

• OpenGL ES

As a final treat, weʼll play with• OpenGL ES• and the iPhoneʼs accelerometer.

Page 265: iPhone Development Overview

GLGravity

• OpenGL ES

• Accelerometer

As a final treat, weʼll play with• OpenGL ES• and the iPhoneʼs accelerometer.

Page 266: iPhone Development Overview

These are our three examples.

Page 267: iPhone Development Overview

Let’s get started.

Letʼs get started.