Upload
pete-goodliffe
View
4.099
Download
0
Embed Size (px)
Citation preview
iPhone development a brief introduction pete goodliffe
iPhoneDevelopmenta brief introduction
Pete [email protected]
ACCU 2010
Hello,world!
iPhone development a brief introduction pete goodliffe
Pete GoodliffeA programmer, a columnist, an author, a teacher. Someone who cares about code.
www.goodliffe.netgoodliffe.blogspot.com
@petegoodliffe
iPhone development a brief introduction pete goodliffe
Pete GoodliffeA programmer, a columnist, an author, a teacher. Someone who cares about code.
www.goodliffe.netgoodliffe.blogspot.com
@petegoodliffe
iPhone development a brief introduction pete goodliffe
An introduction to iPhone developmentAn introduction to iPhone development for beginners or those who are casually interested and want a leg up the learning curve.
This talk is an overview of how to get started as an iPhone developer, and an introduction to the core technologies, including:
‣ Common iPhone/Mac OS design patterns, idioms, and practices‣ Becoming a native: how to "think in iPhone"‣ Overview of the libraries and facilities that exist‣ Limitations of the development environment
talk synopsis
iPhone development a brief introduction pete goodliffe
iPhone development a brief introduction pete goodliffe
90 minutes? is that all?!!!
iPhone development a brief introduction pete goodliffe
Intro
Tools
Language
UITechnologies
Deploying
Further info
Tips
Demoin 90 minutes...
‣ Intro‣ The tools‣ The language‣ The UI‣ Key technologies‣ Deploying‣ Further info‣ Tips and tricks‣ The demo
Mmm… pie
iPhone development a brief introduction pete goodliffe
Intro
Tools
Language
UITechnologies
Deploying
Further info
Tips
Demoin 90 minutes...
‣ Intro‣ The tools‣ The language‣ The UI‣ Key technologies‣ Deploying‣ Further info‣ Tips and tricks‣ The demo
Introduction
iPhone development a brief introduction pete goodliffe
who are you?
iPhone development a brief introduction pete goodliffe
why developfor the iPhone?
iPhone development a brief introduction pete goodliffe
the alternatives
iPhone development a brief introduction pete goodliffe
Intro
Tools
Language
UITechnologies
Deploying
Further info
Tips
Demoin 90 minutes...
‣ Intro‣ The tools‣ The language‣ The UI‣ Key technologies‣ Deploying‣ Further info‣ Tips and tricks‣ The demo
iPhone development a brief introduction pete goodliffe
Intro
Tools
Language
UITechnologies
Deploying
Further info
Tips
Demoin 90 minutes...
‣ Intro‣ The tools‣ The language‣ The UI‣ Key technologies‣ Deploying‣ Further info‣ Tips and tricks‣ The demo
iPhone development a brief introduction pete goodliffe
Intro
Tools
Language
UITechnologies
Deploying
Further info
Tips
Demoin 90 minutes...
‣ Intro‣ The tools‣ The language‣ The UI‣ Key technologies‣ Deploying‣ Further info‣ Tips and tricks‣ The demo
The tools
iPhone development a brief introduction pete goodliffe
❖ The cast ❖
XcodeiPhone/iPod Touch/iPad
Interface builderiPhone simulator
Instruments/SharkOther tools
iPhone development a brief introduction pete goodliffe
Xcode
iPhone development a brief introduction pete goodliffe
iPhone development a brief introduction pete goodliffe
iPhone development a brief introduction pete goodliffe
an iPhone
iPhone development a brief introduction pete goodliffe
Interface Builder
iPhone development a brief introduction pete goodliffe
iPhone simulator
iPhone development a brief introduction pete goodliffe
Instruments/Shark
iPhone development a brief introduction pete goodliffe
Other tools
iPhone development a brief introduction pete goodliffe
Getting set up...
Get a MacGet the tools
InstallGet an ADC account
Code…
Profit
$$$
iPhone development a brief introduction pete goodliffe
Intro
Tools
Language
UITechnologies
Deploying
Further info
Tips
Demoin 90 minutes...
‣ Intro‣ The tools‣ The language‣ The UI‣ Key technologies‣ Deploying‣ Further info‣ Tips and tricks‣ The demo
iPhone development a brief introduction pete goodliffe
Intro
Tools
Language
UITechnologies
Deploying
Further info
Tips
Demoin 90 minutes...
‣ Intro‣ The tools‣ The language‣ The UI‣ Key technologies‣ Deploying‣ Further info‣ Tips and tricks‣ The demo
iPhone development a brief introduction pete goodliffe
Intro
Tools
Language
UITechnologies
Deploying
Further info
Tips
Demoin 90 minutes...
‣ Intro‣ The tools‣ The language‣ The UI‣ Key technologies‣ Deploying‣ Further info‣ Tips and tricks‣ The demo
The language
iPhone development a brief introduction pete goodliffe
(well, languages)C
C++Objective-C
iPhone development a brief introduction pete goodliffe
iPhone development a brief introduction pete goodliffe
a history of objective-c in 14
lines and 12 words(give or take)
iPhone development a brief introduction pete goodliffe
algol
CPLBCPLBC
Simula
Smalltalk
Objective-C
C++
Java C# D
iPhone development a brief introduction pete goodliffe
objective C is...dynamic
based on message passingfollows C compilation model
full of [ ] and @s
- (id) thisIsAMethod:(int)param1 signatute:(float)param2{ for (int n = 0; n < 10; ++n) { NSLog(@”N=%d”, n); [object callMethod:1 thing:2]; }}
not too
scary!
(brace yourself)
iPhone development a brief introduction pete goodliffe
- (id) thisIsAMethod:(int)param1 signatute:(float)param2{ for (int n = 0; n < 10; ++n) { NSLog(@”N=%d”, n); [object callMethod:1 thing:2]; }}
@implementation MyClass
@end
.m file
iPhone development a brief introduction pete goodliffe
- (id) thisIsAMethod:(int)param1 signatute:(float)param2{ for (int n = 0; n < 10; ++n) { NSLog(@”N=%d”, n); [object callMethod:1 thing:2]; }}
@implementation MyClass
@end
@class@interface@implementation@end@property@private@protected
iPhone development a brief introduction pete goodliffe
- (id) thisIsAMethod:(int)param1 signatute:(float)param2{ for (int n = 0; n < 10; ++n) { NSLog(@”N=%d”, n); [object callMethod:1 thing:2]; }}
@implementation MyClass
@end
iPhone development a brief introduction pete goodliffe
- (id) thisIsAMethod:(int)param1 signatute:(float)param2{ for (int n = 0; n < 10; ++n) { NSLog(@”N=%d”, n); [object callMethod:1 thing:2]; }}
@implementation MyClass
@end
iPhone development a brief introduction pete goodliffe
- (id) thisIsAMethod:(int)param1 signatute:(float)param2{ for (int n = 0; n < 10; ++n) { NSLog(@”N=%d”, n); [object callMethod:1 thing:2]; }}
@implementation MyClass
@end
iPhone development a brief introduction pete goodliffe
- (id) thisIsAMethod:(int)param1 signatute:(float)param2{ for (int n = 0; n < 10; ++n) { NSLog(@”N=%d”, n); [object callMethod:1 thing:2]; }}
@implementation MyClass
@end
Can still write (and call)
C free functions
iPhone development a brief introduction pete goodliffe
- (id) thisIsAMethod:(int)param1 signatute:(float)param2{ for (int n = 0; n < 10; ++n) { NSLog(@”N=%d”, n); [object callMethod:1 thing:2]; }}
@implementation MyClass
@end
NSString
iPhone development a brief introduction pete goodliffe
- (id) thisIsAMethod:(int)param1 signatute:(float)param2{ for (int n = 0; n < 10; ++n) { NSLog(@”N=%d”, n); [object callMethod:1 thing:2]; }}
@implementation MyClass
@end
iPhone development a brief introduction pete goodliffe
- (id) thisIsAMethod:(int)param1 signatute:(float)param2{ for (int n = 0; n < 10; ++n) { NSLog(@”N=%d”, n); [object callMethod:1 thing:2]; }}
@implementation MyClass
@end
Can call nil
iPhone development a brief introduction pete goodliffe
[object method];int i = [object method]; [[object method1] method2];
[object method:10]; [object1 method:[object 2:method]];
Sending messages
iPhone development a brief introduction pete goodliffe
Method names
[circle setCenterAtX:(float)x y:(float)y];
object
parameters
method name
method name is: setCenterAtX:y:
SEL s = @selector(setCenterAtX:y:); [circle performSelector:s];
iPhone development a brief introduction pete goodliffe
parameter types:int, float, unsigned, etcsyntax: (return type)
id
iPhone development a brief introduction pete goodliffe
@class ForwardDeclaration;
@interface MyClass : NSObject{ ForwardDeclaration *member; bool otherMember;}
- (void) init;- (id) initWithItems:(NSArray*)array enabled:(bool)enabled;
+ (id) myClassWithItems:(NSArray*)array;
@end
.h file
iPhone development a brief introduction pete goodliffe
@class ForwardDeclaration;
@interface MyClass : NSObject{ ForwardDeclaration *member; bool otherMember;}
- (void) init;- (id) initWithItems:(NSArray*)array enabled:(bool)enabled;
+ (id) myClassWithItems:(NSArray*)array;
@end
iPhone development a brief introduction pete goodliffe
@class ForwardDeclaration;
@interface MyClass : NSObject{ ForwardDeclaration *member; bool otherMember;}
- (void) init;- (id) initWithItems:(NSArray*)array enabled:(bool)enabled;
+ (id) myClassWithItems:(NSArray*)array;
@end
iPhone development a brief introduction pete goodliffe
@class ForwardDeclaration;
@interface MyClass : NSObject{ ForwardDeclaration *member; bool otherMember;}
- (void) init;- (id) initWithItems:(NSArray*)array enabled:(bool)enabled;
+ (id) myClassWithItems:(NSArray*)array;
@end
iPhone development a brief introduction pete goodliffe
@class ForwardDeclaration;
@interface MyClass : NSObject{ ForwardDeclaration *member; bool otherMember;}
- (void) init;- (id) initWithItems:(NSArray*)array enabled:(bool)enabled;
+ (id) myClassWithItems:(NSArray*)array;
@end
iPhone development a brief introduction pete goodliffe
@class ForwardDeclaration;
@interface MyClass : NSObject{ ForwardDeclaration *member; bool otherMember;}
- (void) init;- (id) initWithItems:(NSArray*)array enabled:(bool)enabled;
+ (id) myClassWithItems:(NSArray*)array;
@end
iPhone development a brief introduction pete goodliffe
@class ForwardDeclaration;
@interface MyClass : NSObject{ ForwardDeclaration *member; bool otherMember;}
- (void) init;- (id) initWithItems:(NSArray*)array enabled:(bool)enabled;
+ (id) myClassWithItems:(NSArray*)array;
@end
iPhone development a brief introduction pete goodliffe
@class ForwardDeclaration;
@interface MyClass : NSObject{ ForwardDeclaration *member; bool otherMember;}
- (void) init;- (id) initWithItems:(NSArray*)array enabled:(bool)enabled;
+ (id) myClassWithItems:(NSArray*)array;
@end
iPhone development a brief introduction pete goodliffe
Objective C++In .mm files
Classes can contain C++ objectsMay use in functions
You can use RAIIC++ libraries
iPhone development a brief introduction pete goodliffe
@interface MyClass { int harold; } @property (nonatomic,assign) int harold; @end
In MyClass.m... @interface MyClass @synthesize harold; @end
Properties
This will become important when we look at creating UIs
iPhone development a brief introduction pete goodliffe
The tao of objectsYou don’t call methods
You pass messages to objects
[theObject sendMessage:parameter];
iPhone development a brief introduction pete goodliffe
object.myMethod(1066);
Java, C++, C#
class MyClass{ public myMethod(int i) { // ... }};
MyClass
myMethod(int)
another()
more()
private data
MyClass *this
iPhone development a brief introduction pete goodliffe
[object myMethod:1066];
Objective-C
@implementation MyClass- (void) myMethod:(int)i{ // ...}@end
MyClass
myMethod(int)
another()
private data
MyClass *self
message (selector)
iPhone development a brief introduction pete goodliffe
@interface NSObject (Foo)- (void) extraFooMethod;@end
NSArray *array = [NSArray array];[array extraFooMethod];
Categories
iPhone development a brief introduction pete goodliffe
NSArray *array1 = [[NSArray alloc] init];NSArray *array2 = [NSArray array];
[array1 release];[array2 release]; // wrong
Circle *circle = [[Circle alloc] initAtCenterX:100 y:100 radius:200];
Object lifetimeAll objects are reference counted
(the retain count)
iPhone development a brief introduction pete goodliffe
Action Retain count
[[object alloc] init]; 1
[object retain]; 2
[object release]; 1
[object release]; 0
[object dealloc];
iPhone development a brief introduction pete goodliffe
NSObjectNSStringNSArray NSMutableArrayNSNumberNSThreadNSDictionary NSMutableDictionaryNSApplicationNSData NSMutableDataNSURLNSSet NSMutableSetNSValue
The usual suspects
iPhone development a brief introduction pete goodliffe
Statically typed my arse#import
iPhone development a brief introduction pete goodliffe
Idioms
DelegatesKey-value coding
Protocol (interfaces)formal and informal
iPhone development a brief introduction pete goodliffe
The libraries
Cocoa Touch
Media
Core Services
Core OSC
Objective C
Posix,SQLite, Core Foundation, BSD
Core Audio, Open GL ES, Quartz, Core Animation
UIKit, etc
iPhone development a brief introduction pete goodliffe
Intro
Tools
Language
UITechnologies
Deploying
Further info
Tips
Demoin 90 minutes...
‣ Intro‣ The tools‣ The language‣ The UI‣ Key technologies‣ Deploying‣ Further info‣ Tips and tricks‣ The demo
iPhone development a brief introduction pete goodliffe
Intro
Tools
Language
UITechnologies
Deploying
Further info
Tips
Demoin 90 minutes...
‣ Intro‣ The tools‣ The language‣ The UI‣ Key technologies‣ Deploying‣ Further info‣ Tips and tricks‣ The demo
iPhone development a brief introduction pete goodliffe
Intro
Tools
Language
UITechnologies
Deploying
Further info
Tips
Demoin 90 minutes...
‣ Intro‣ The tools‣ The language‣ The UI‣ Key technologies‣ Deploying‣ Further info‣ Tips and tricks‣ The demo
The UI
iPhone development a brief introduction pete goodliffe
Interface Builder
iPhone development a brief introduction pete goodliffe
Held in .xib files(Compiled NIBs)
Loaded into application (semi-automatically)
IB is tightly integrated with Xcode
UIKit framework
iPhone development a brief introduction pete goodliffe
iPhone development a brief introduction pete goodliffe
Create UI elements
Link to an object reference in the XIB through properties
marked as IBOutlet
Link actions to methods defined IBAction
iPhone development a brief introduction pete goodliffe
//// ExampleAppDelegate.h// Example//// Created by Pete Goodliffe on 03/04/2010.// Copyright __MyCompanyName__ 2010. All rights reserved.//
#import <UIKit/UIKit.h>
@interface ExampleAppDelegate : NSObject <UIApplicationDelegate> { UIWindow *window; UINavigationController *navigationController;}
@property (nonatomic, retain) IBOutlet UIWindow *window;@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
@end
iPhone development a brief introduction pete goodliffe
Intro
Tools
Language
UITechnologies
Deploying
Further info
Tips
Demoin 90 minutes...
‣ Intro‣ The tools‣ The language‣ The UI‣ Key technologies‣ Deploying‣ Further info‣ Tips and tricks‣ The demo
iPhone development a brief introduction pete goodliffe
Intro
Tools
Language
UITechnologies
Deploying
Further info
Tips
Demoin 90 minutes...
‣ Intro‣ The tools‣ The language‣ The UI‣ Key technologies‣ Deploying‣ Further info‣ Tips and tricks‣ The demo
iPhone development a brief introduction pete goodliffe
Intro
Tools
Language
UI
Technologies
Deploying
Further info
Tips
Demoin 90 minutes...
‣ Intro‣ The tools‣ The language‣ The UI‣ Key technologies‣ Deploying‣ Further info‣ Tips and tricks‣ The demo
Key technologies
iPhone development a brief introduction pete goodliffe
UIKitCore Graphics
Core AudioMedia Core / AVFoundation
MapKit / Core LocationCoreData (or sqlite)
OpenGL ESExternal Accessory
iPhone development a brief introduction pete goodliffe
Intro
Tools
Language
UI
Technologies
Deploying
Further info
Tips
Demoin 90 minutes...
‣ Intro‣ The tools‣ The language‣ The UI‣ Key technologies‣ Deploying‣ Further info‣ Tips and tricks‣ The demo
iPhone development a brief introduction pete goodliffe
Intro
Tools
Language
UITechnologies
Deploying
Further info
Tips
Demoin 90 minutes...
‣ Intro‣ The tools‣ The language‣ The UI‣ Key technologies‣ Deploying‣ Further info‣ Tips and tricks‣ The demo
iPhone development a brief introduction pete goodliffe
Intro
Tools
Language
UITechnologies
Deploying
Further info
Tips
Demoin 90 minutes...
‣ Intro‣ The tools‣ The language‣ The UI‣ Key technologies‣ Deploying‣ Further info‣ Tips and tricks‣ The demo
Deploying
iPhone development a brief introduction pete goodliffe
iPhone simulator
DeployingiPhone
App store
freex86
runs at desktop speedmore memorynetwork stable
developer account ($$$)“DRM hell”
Deployment certificates100 devices per year
iTunes connectAnother build type
different build targets
iPhone development a brief introduction pete goodliffe
App store
submit
get rejected
fix it
resubmit
profit
iPhone development a brief introduction pete goodliffe
Intro
Tools
Language
UITechnologies
Deploying
Further info
Tips
Demoin 90 minutes...
‣ Intro‣ The tools‣ The language‣ The UI‣ Key technologies‣ Deploying‣ Further info‣ Tips and tricks‣ The demo
iPhone development a brief introduction pete goodliffe
Intro
Tools
Language
UITechnologies
Deploying
Further info
Tips
Demoin 90 minutes...
‣ Intro‣ The tools‣ The language‣ The UI‣ Key technologies‣ Deploying‣ Further info‣ Tips and tricks‣ The demo
iPhone development a brief introduction pete goodliffe
Intro
Tools
Language
UITechnologies
Deploying
Further info
Tips
Demoin 90 minutes...
‣ Intro‣ The tools‣ The language‣ The UI‣ Key technologies‣ Deploying‣ Further info‣ Tips and tricks‣ The demo
Further info
iPhone development a brief introduction pete goodliffe
Xcode documentationdeveloper.apple.com/iphone
BooksWebsites
Stack Overflow, CocoaDev, ADC
Videos on iTunes Uhttp://itunes.stanford.edu/
iPhone development a brief introduction pete goodliffe
Intro
Tools
Language
UITechnologies
Deploying
Further info
Tips
Demoin 90 minutes...
‣ Intro‣ The tools‣ The language‣ The UI‣ Key technologies‣ Deploying‣ Further info‣ Tips and tricks‣ The demo
iPhone development a brief introduction pete goodliffe
Intro
Tools
Language
UITechnologies
Deploying
Further info
Tips
Demoin 90 minutes...
‣ Intro‣ The tools‣ The language‣ The UI‣ Key technologies‣ Deploying‣ Further info‣ Tips and tricks‣ The demo
iPhone development a brief introduction pete goodliffe
Intro
Tools
Language
UITechnologies
Deploying
Further info
Tips
Demoin 90 minutes...
‣ Intro‣ The tools‣ The language‣ The UI‣ Key technologies‣ Deploying‣ Further info‣ Tips and tricks‣ The demo
Tipsand tricks
iPhone development a brief introduction pete goodliffe
Thinking iPhone
iPhone development a brief introduction pete goodliffe
Get the UI right
HIGresource conservation
(alpha blending, prerendering)
iPhone development a brief introduction pete goodliffe
The network is not always available
iPhone development a brief introduction pete goodliffe
Do not write to disk(often)
iPhone development a brief introduction pete goodliffe
Conserve resources
RAMCPU
filesystem
iPhone development a brief introduction pete goodliffe
Intro
Tools
Language
UITechnologies
Deploying
Further info
Tips
Demoin 90 minutes...
‣ Intro‣ The tools‣ The language‣ The UI‣ Key technologies‣ Deploying‣ Further info‣ Tips and tricks‣ The demo
iPhone development a brief introduction pete goodliffe
Intro
Tools
Language
UITechnologies
Deploying
Further info
Tips
Demoin 90 minutes...
‣ Intro‣ The tools‣ The language‣ The UI‣ Key technologies‣ Deploying‣ Further info‣ Tips and tricks‣ The demo
iPhone development a brief introduction pete goodliffe
Intro
Tools
Language
UITechnologies
Deploying
Further info
Tips
Demoin 90 minutes...‣ Intro‣ The tools‣ The language‣ The UI‣ Key technologies‣ Deploying‣ Further info‣ Tips and tricks‣ The demo
The demo
iPhone development a brief introduction pete goodliffe
(wish me luck)
wasn’t that marvellous?!
iPhone development a brief introduction pete goodliffe
Pete [email protected]