Quand débuter les antirétroviraux? Recommandations internationales
CocoaHeads Rennes #3 : Bien débuter sur iOS
-
Upload
cocoaheadsrns -
Category
Technology
-
view
903 -
download
1
description
Transcript of CocoaHeads Rennes #3 : Bien débuter sur iOS
Bien débuter sur
Jérémy Brault
CocoaHeads Rennes8 septembre 2011
Objective-C : descriptif
• Surcouche C
• Orienté objet
• Inspiré de SmallTalk
• Typage dynamique, héritage simple
Objective-C : classe@interface Employee : Person {
float salary_;
float bonus_;
Boss *boss_;
}
- (float)monthlyPay;
+ (uint)numberOfEmployees;
@end
Objective-C : classe@implementation Employee
- (float)monthlyPay {
return (salary_ + bonus_) / 12;
}
+ (uint)numberOfEmployees {
return nbInstances;
}
@end
Objective-C : protocole@protocol SubscriptionListener <Listener>
@required
- (void)didSubscribe;
@optional
- (void)didUnsubscribe;
@end
Objective-C : protocole@interface Employee : Person <SubscriptionListener> {
}
@end
@implementation Employee
- (void)didSubscribe {
...
}
@end
Objective-C : messagerq1-> comparaison Java (importance des étiquettes)
Color* color = Color.createColor(0.2, 0.4, 0.7, 0.6);
Color* color = [Color createColorRed:0.2 green:0.4 blue:0.7 alpha:0.6];+ (Color*)createColorRed:(float)red green:(float)green blue:(float)blue alpha:(float)alpha;
[[Color redColor] colorByAddingBlue:0.2];
+ (Color*)redColor;
- (Color*)colorByAddingBlue:(float)blueValue;
Color* myColor = [Color redColor];
myColor = [myColor colorByAddingBlue:0.2];
Objective-C : instance
• Appel sur la classe courante : self
• Appel sur la super-classe : super
Objective-C : création d’objet
• Allocation mémoire : alloc
• Initialisation : init
Person *john = [[Person alloc] init];
Objective-C : initialiseur
- (id)initWithIndex:(int)index {
self = [super init];
if (self) {
index_ = index;
}
return self;
}
Objective-C :gestion mémoire
• Compteur de références : retainCount
employee
boss1 boss2
2
• 0 : dealloc
• release, autorelease : -1• alloc, copy, retain : +1
Objective-C :gestion mémoire
“ You are responsible for the objects you own ”
alloc/copy/retain release/autorelease
Gestion mémoire : variable locale
- (void)doSomeWork {
Job *boringJob = [[Job alloc] init];
...
[boringJob release];
}
- (void)drinkHotBeverage {
Cofee *cofee = [[[Cofee alloc] init] autorelease];
...
}
Gestion mémoire : variable d’instance
- (id)initWithBoss:(Boss*)boss {
self = [super init];
if (self) {
boss_ = [boss retain];
}
return self;
}
- (void)dealloc {
[boss_ release];
[super dealloc];
}
Objective-C : getter & setter
@interface Employee : Person {
float salary_;
Boss *boss_;
}
@property (assign) float salary;
@property (retain) Boss *boss;
@end
Objective-C : getter & setter
@implementation Employee
@synthesize salary = salary_;
@synthesize boss = boss_;
@end
Développer sur iOS : API
• CocoaTouch
• Descendant de Cocoa
• Design MVC
• Foundation Kit
• UIKit
• CoreData
Développer sur iOS : outils
• XCode
• InterfaceBuilder
• GCC/GCD, LLVM/LLDB
• Instruments
CocoaTouch par l’exemple (1) : vue
• UIView
• Dessin
• Hiérarchie
• Interaction
• Customisation
• Sous-classes : UILabel, UIButton, etc.
DEMO
CocoaTouch par l’exemple (2) : contrôleur• UIViewController
• Gestion d’une hiérarchie de vues
• Médiation entre données et vues
• Logique de navigation
• Sous-classes : UINavigationController, UITableViewController, etc.
DEMO
Must know-Must read• Documentation & Forum Apple
• Forum PommeDev
• StackOverflow
• CocoaHeads
• “ Beginning iPhone Development : exploring the iPhone SDK ”, APress