More Related Content
Similar to Objective C (20)
Objective C
- 1. Objective-C
vs. C++ / Java
Studenckie Koło Naukowe “MacKN”
Błażej Biesiada
- 2. Agenda
• Co to jest Obj-C?
• Historia
• Dlaczego Obj-c?
• Składnia
• Elementy charakterystyczne
• Co dalej?
- 3. Co to jest Obj-C?
• skrót od Objective-C ;-)
• rozszerzenie języka C
• obiektowość oparta na Smalltalku-u
• wykorzystywany głównie w Mac OS X
- 4. Historia
StepStone NeXT GNU Obj-C
1986 1988 1993
Apple Mac OS X Obj-C 2.0
1996 2001 2007
- 6. [obj msg] vs. obj.met()
[obiekt wiadomosc];
[obiekt wiadomosc: arg1: arg2: arg3];
[obiekt ustawSzerokosc: arg1 Wysokosc: arg2 Glebokosc: arg3];
- 7. *.m vs. *.cpp
//ClassName.h //ClassName.m
@interface ClassName : ItsSuperclass @implementation ClassName
{ + (id)alloc {
float height;
//...
BOOL filled; }
NSColor *fillColor; - (void)display {
}
//...
+ (id)alloc; }
- (void)display; @end
@end
- 8. val / setVal vs. getVal / setVal
• sekcje @private, @protected, @public
• domyślnie @protected
• Key Value Coding, czyli nie tylko konwencja
- 9. id vs. void
• id - typ wskaźnikowy
• void - brak wyniku funkcji
• NIL - obiekt używany zamiast NULL
- 10. @try vs. try
Cup *cup = [[Cup alloc] init];
@try {
[cup fill];
}
@catch (NSException *exception) {
NSLog(@quot;main: Caught %@: %@quot;, [exception name], [exception reason]);
}
@finally {
[cup release];
}
- 11. protokoły vs. interfejsy
@protocol MyProtocol
@interface MyClass ( MyProtocol )
- (void)requiredMethod;
{
@optional
int myVal;
- (void)anOptionalMethod;
}
- (void)anotherOptionalMethod;
- (void)myOwnClassMethod;
@required
@end
- (void)anotherRequiredMethod;
@end
- 14. Properties, czyli coś nowego
@interface MyClass : NSObject
{
NSString *value;
}
@property(copy, readwrite) NSString *value;
@end
@implementation MyClass
@synthesize value;
@end