View
973
Download
0
Embed Size (px)
DESCRIPTION
Citation preview
iOS App 101And how fun is it ?
by tomjpsun
1275
About me
MFC Certificate WDM driver (USB)
1275
About me
MFC Certificate WDM driver (USB)
Linux driver iOS App
1275
About me
MFC Certificate WDM driver (USB)
Linux driver iOS App
1275
About me
MFC Certificate WDM driver (USB)
Linux driver iOS App
1275
About me
MFC Certificate WDM driver (USB)
Linux driver iOS App
Not interest any more
1275
Agenda
Development Environment Objective-C Cocoa Design patterns UX References
1275
Agenda
Development Environment Objective-C Cocoa Design patterns UX References
1275
XCode
iOS ver XCode ver
OS X ver
5.1 4.3 10.7(Lion)
5.0 below 4.2 10.6.8(Leopard)
Strictly depends on
Tested combinations
1275
https://developer.apple.com/programs/
1275
iOS Dev Centerhttps://developer.apple.com/devcenter/ios/index.action
1275
Provision profile
Your Mac Dev Center
1275
Demo Create an empty App Browse XCode features organizer project configurations simulator download debug
1275
Agenda
Development Environment Objective-C Cocoa Design patterns UX References
1275
Object oriented
1275
Message passing
[instance method];
iOS
1275
Dynamismobjective-C runtime library
1275
.h#import
@interface Fraction: NSObject{ int numerator; int denominator;}-(void) print;-(void) setNumerator: (int) n;-(void) setDenominator: (int) d;@end
1275
.m#import "Fraction.h"
@implementation Fraction-(void) print{ NSLog(@"%i/%i", numerator, denominator);}-(void) setNumerator: (int) n{ numerator = n;}-(void) setDenominator: (int) d{ denominator = d;}@end
1275
Multiple arguments-(void) setTo: (int) n over: (int) d
{ numerator = n; denominator = d;}
int main (int argc, char *argv[]){ Fraction *aFraction = [[Fraction alloc] init]; [aFraction setTo: 1 over: 3]; [aFraction print]; // -> 1/3 return 0;}
1275
Class method@interface Fraction: NSObject{ int numerator; int denominator;}
@interface FractionFactory: NSObject
+(Fraction*) newFractionWithNumerator: (int)numerator andDenominator: (int)denominator;
int main (int argc, char *argv[]){ Fraction* f = [FractionFactory newFractionWithNumerator: 1 andDenominator: 2];}
1275
Synthesized accessor#import
@interface Fraction: NSObject{ int numerator;}-(void) setNumerator: (int) n; // setter-(int) numerator; // getter@end
@interface Fraction: NSObject@property numerator;@end
@implementation Fraction@synthesis numerator;@end
compiler generates getter/setter
1275
Dot accessing property[ instance setPoperty: 2];
is equal to
instance.property = 2;
1275
self
self like this in C++- (id)init{ self = [super init]; if (self) { // Custom initialization } return self;}
1275
id
something like void* useful at runtime
1275
selector
name of method , function literal compile time
SEL aSelector = @selector(methodName);
run timeSEL aSelector = NSSelectorFromString(@"print"); NSString* selectorStr =
NSStringFromSelector(aSelector);
NSLog(@"%@", selectorStr);
1275
selector[friend performSelector:@selector(gossipAbout:)
withObject:aNeighbor];
is equal to
[friend gossipAbout:aNeighbor];
1275
Runtime library
compile time, link time run time
1275
object A-(void)fly
object B-(void)fly
SEL userSelector = NSSelectorFromString(@fly);[ any performSelector: @selector(userSelector) ];
any object A, A flyany object B, B fly
1275
Category extending class (even if you dont have the
source)
#import "High.h"
@interface High (calculate)- (NSInteger) plus:(NSInteger)operand1 and:(NSInteger)operand2;@end
@implementation High (calculate)- (NSInteger) plus:(NSInteger)operand1 and:(NSInteger)operand2{ return operand1 + operand2;}@end
1275
Class extension
category without name used as private method declaration in Obj-
C
1275
Category may cause chaos
category wins over the override function define same function in different
categories. Lead to undefined condition.
1275
@protocol
class with only methods. classes functions.
@protocol MyXMLSupport
- initFromXMLRepresentation:(NSXMLElement *)XMLElement;
- (NSXMLElement *)XMLRepresentation;
@end
1275
memory management
MRC - manual reference counting ARC - automatic reference counting garbage collection - in OS X, not in iOS
1275
MRC
Apples rule - owner release (owner: copy, alloc, retain)
burden on developers// retain release pairid value = [dict retain];[value release];
// autoreleasearray = [[NSMutableArray new] autorelease];
1275
ARC
supported on LLVM 3.0 generate release code for you.
1275
Blocksthis section is borrowed from WWDC 2011, sec. block
and central dispatch
* ^1275
Functions Blocks
// body of code{
return a - b;
}
// pointer to a function*
// body of code{
return a - b;
}
// pointer to a block^
1275
Functions Blocks
// body of code{
return a - b;
}
// pointer to a functionint (*cmpr)(int, int);
// body of code{
return a - b;
}
// pointer to a blockint (^cmpr)(int, int);
1275
Functions Blocks
// body of code{
return a - b;
}
// pointer to a functionint (*cmpr)(int, int);
typedef int (*func_t) (int, int);
// body of code{
return a - b;
}
// pointer to a blockint (^cmpr)(int, int);
typedef int (^block_t)(int, int);
1275
Functions Blocks
// body of code{
return a - b;
}
// pointer to a functionint (*cmpr)(int, int);
typedef int (*func_t) (int, int);
func_t cmpr = arg;
// body of code{
return a - b;
}
// pointer to a blockint (^cmpr)(int, int);
typedef int (^block_t)(int, int);
block_t cmpr = arg;
1275
Functions Blocks
// body of code{
return a - b;
}
// pointer to a functionint (*cmpr)(int, int);
typedef int (*func_t) (int, int);
func_t cmpr = arg;
cmpr(x, y);
// body of code{
return a - b;
}
// pointer to a blockint (^cmpr)(int, int);
typedef int (^block_t)(int, int);
block_t cmpr = arg;
cmpr(x, y);
1275
Functions Blocks
// body of code{
return a - b;
}
// pointer to a function*
// body of code{
return a - b;
}
// pointer to a block^
1275
Functions Blocks
// body of codeint my_cmp(int a, int b){
return a - b;
}
// body of code^(int a, int b){
return a - b;
}
1275
Functions Blocks
// body of code
int my_cmp(int a, int b){
return a - b;
}
// usage
sort(array, 10, my_cmp);
// body of code
^(int a, int b){
return a - b;
}
// usage
sort(array, 10, ^(int a, int b){ return a - b;});
1275
Blocks
// body of code
^(int a, int b){
return a - b;
}
closure
1275
Blocks
// body of code__block int cnt = 0;^(int a, int b){ cnt++ ; return a - b;
}
log(Count: %d, cnt);
closure
1275
Agenda
Development Environment Objective-C Cocoa Design patterns UX References
1275
Cocoa fit in iOS
App UIKit
1275
UIKit Philosophy
MVC
1275
View Controllers
1275
Anatomy
1275
View Controllers Manage Views
1275
View Controllers Manage Views
1275
View Controllers Manage Views
1275
View
1275
Important Documents
View Controller Programming Guide for iOSView Programming Guide
1275
Agenda
Development Environment Objective-C Cocoa Design patterns UX References
1275
delegate
iOSUIApplication
object
MyAppdelegate
implemented via @protocol
1275
delegate
iOSUIApplication
object
MyAppApp
delegateimplemented via @protocol
1275
delegate
iOSUIApplication
object
MyAppApp
delegateimplemented via @protocol
1275
delegate
iOSUIApplication
object
MyAppApp
delegateimplemented via @protocol
1275
delegate
iOSUIApplication
object
MyAppdelegate
implemented via @protocol
1275
delegate
iOSUIApplication
object
MyAppApp
delegateimplemented via @protocol
1275
delegate
iOSUIApplication
object
MyAppApp
delegateimplemented via @protocol
App
1275
delegate
iOSUIApplication
object
MyAppdelegate
implemented via @protocol
@protocol
1275
delegate
iOSUIApplication
object
MyAppdelegate
implemented via @protocol
some delegatesare optional
@protocol
1275
delegate
no need to subclassing everywhere. de-coupling decision, cleaner design.
1275
delegate demo
https://github.com/tomjpsun/TestObjc.git
1275
Data-Source
nearly the same as delegate, data UI .
TableView Controller
sections ?
4
sec 1 cell 1
Clear History
1275
Data-Source
nearly the same as delegate, data UI .
TableView Controller
sections ?
4
sec 1 cell 1
Clear History
Data Source
1275
Target-Action
- (void)viewDidLoad{ [super viewDidLoad];! [self.myButton addTarget:self action:@selector(myButtonPressed:) forControlEvents:UIControlEventTouchUpInside];}
- (void)myButtonPressed:(UIButton*)button{ ...}
ViewController-(void)myButtonPressed:
Buttonsend message when the event occurs
1275
Notification
Notification Center
anObject
observer 1
observer 2
observer 3
post notification
broadcast notification
reduce the code coupling
1275
Singleton
instance shared .
Typical class
request 1
response 1A
request 2
response 2 B
Singleton
request 1
response 1A
request 2
response 2
1275
Singleton
design pattern ? Cocoa singleton pattern
NSFileManagerNotification Center
UIApplication
1275
Agenda
Development Environment Objective-C Cocoa Design patterns UX References
1275
Get it done quick
abstract from the Tap Worthy book
1275
Get it done quick
abstract from the Tap Worthy book
1275
Get it done quick
abstract from the Tap Worthy book
1275
abstract from the Tap Worthy book
1275
abstract from the Tap Worthy book
1275
44abstract from the Tap Worthy book
1275
Agenda
Development Environment Objective-C Cocoa Design patterns UX References
1275
Agenda
Development Environment Objective-C Cocoa Design patterns UX References
1275
Objective-C
http://www.amazon.com/Programming-Objective-C-2-0-2nd-Edition/dp/0321566157
1275
Cocoa
http://www.amazon.com/Cocoa-Design-Patterns-Erik-Buck/dp/0321535022/ref=sr_1_1?s=books&ie=UTF8&qid=1341483494&sr=1-1&keywords=cocoa+design+patterns
1275
Online Videos
CS193p in iTunes U(niversity)
1275
User Experience
http://www.amazon.com/Tapworthy-Designing-Great-iPhone-Apps/dp/1449381650/ref=sr_1_1?s=books&ie=UTF8&qid=1341483149&sr=1-1&keywords=tapworthy
1275
XCode documents
1275
XCode documents
1275
Q & A
1275