Objective C
-
Upload
konryd -
Category
Technology
-
view
2.646 -
download
5
description
Transcript of Objective C
![Page 1: Objective C](https://reader033.fdocuments.us/reader033/viewer/2022052412/558e133a1a28ab67128b47a6/html5/thumbnails/1.jpg)
Objective-Cvs. C++ / Java
Studenckie Koło Naukowe “MacKN”Błażej Biesiada
![Page 2: Objective C](https://reader033.fdocuments.us/reader033/viewer/2022052412/558e133a1a28ab67128b47a6/html5/thumbnails/2.jpg)
Agenda
• Co to jest Obj-C?
• Historia
• Dlaczego Obj-c?
• Składnia
• Elementy charakterystyczne
• Co dalej?
![Page 3: Objective C](https://reader033.fdocuments.us/reader033/viewer/2022052412/558e133a1a28ab67128b47a6/html5/thumbnails/3.jpg)
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
![Page 4: Objective C](https://reader033.fdocuments.us/reader033/viewer/2022052412/558e133a1a28ab67128b47a6/html5/thumbnails/4.jpg)
Historia
StepStone
1986 1988
NeXT
1993
GNU Obj-C
1996
Apple
2001
Mac OS X
2007
Obj-C 2.0
![Page 5: Objective C](https://reader033.fdocuments.us/reader033/viewer/2022052412/558e133a1a28ab67128b47a6/html5/thumbnails/5.jpg)
Dlaczego Obj-C?
• Cocoa
• iPhone OS
• Objective-C 2.0
• A dlaczego C++? Think different!
![Page 6: Objective C](https://reader033.fdocuments.us/reader033/viewer/2022052412/558e133a1a28ab67128b47a6/html5/thumbnails/6.jpg)
[obj msg] vs. obj.met()
[obiekt wiadomosc];
[obiekt wiadomosc: arg1: arg2: arg3];
[obiekt ustawSzerokosc: arg1 Wysokosc: arg2 Glebokosc: arg3];
![Page 7: Objective C](https://reader033.fdocuments.us/reader033/viewer/2022052412/558e133a1a28ab67128b47a6/html5/thumbnails/7.jpg)
*.m vs. *.cpp//ClassName.h
@interface ClassName : ItsSuperclass
{
float height;
BOOL filled;
NSColor *fillColor;
}
+ (id)alloc;
- (void)display;
@end
//ClassName.m
@implementation ClassName
+ (id)alloc {
//...
}
- (void)display {
//...
}
@end
![Page 8: Objective C](https://reader033.fdocuments.us/reader033/viewer/2022052412/558e133a1a28ab67128b47a6/html5/thumbnails/8.jpg)
val / setVal vs. getVal / setVal
• sekcje @private, @protected, @public
• domyślnie @protected
• Key Value Coding, czyli nie tylko konwencja
![Page 9: Objective C](https://reader033.fdocuments.us/reader033/viewer/2022052412/558e133a1a28ab67128b47a6/html5/thumbnails/9.jpg)
id vs. void
• id - typ wskaźnikowy
• void - brak wyniku funkcji
• NIL - obiekt używany zamiast NULL
![Page 10: Objective C](https://reader033.fdocuments.us/reader033/viewer/2022052412/558e133a1a28ab67128b47a6/html5/thumbnails/10.jpg)
@try vs. tryCup *cup = [[Cup alloc] init];
@try {
[cup fill];
}
@catch (NSException *exception) {
NSLog(@"main: Caught %@: %@", [exception name], [exception reason]);
}
@finally {
[cup release];
}
![Page 11: Objective C](https://reader033.fdocuments.us/reader033/viewer/2022052412/558e133a1a28ab67128b47a6/html5/thumbnails/11.jpg)
protokoły vs. interfejsy
@protocol MyProtocol
- (void)requiredMethod;
@optional
- (void)anOptionalMethod;
- (void)anotherOptionalMethod;
@required
- (void)anotherRequiredMethod;
@end
@interface MyClass ( MyProtocol )
{
int myVal;
}
- (void)myOwnClassMethod;
@end
![Page 12: Objective C](https://reader033.fdocuments.us/reader033/viewer/2022052412/558e133a1a28ab67128b47a6/html5/thumbnails/12.jpg)
@synchronized() vs. synchronized
- (void)criticalMethod
{
@synchronized(self) {
// Critical code.
...
}
}
![Page 13: Objective C](https://reader033.fdocuments.us/reader033/viewer/2022052412/558e133a1a28ab67128b47a6/html5/thumbnails/13.jpg)
Inne różnice
• #import vs. #include
• self vs. this
• [super msg] vs. super.met()
![Page 14: Objective C](https://reader033.fdocuments.us/reader033/viewer/2022052412/558e133a1a28ab67128b47a6/html5/thumbnails/14.jpg)
Properties, czyli coś nowego
@interface MyClass : NSObject
{
NSString *value;
}
@property(copy, readwrite) NSString *value;
@end
@implementation MyClass
@synthesize value;
@end
![Page 15: Objective C](https://reader033.fdocuments.us/reader033/viewer/2022052412/558e133a1a28ab67128b47a6/html5/thumbnails/15.jpg)
Kategorie klas#import "ClassName.h"
@interface ClassName ( CategoryName )
// deklaracje metod
@end
#import "ClassName+CategoryName.h"
@implementation ClassName ( CategoryName )
// definicje metod
@end
![Page 16: Objective C](https://reader033.fdocuments.us/reader033/viewer/2022052412/558e133a1a28ab67128b47a6/html5/thumbnails/16.jpg)
Coś więcej?
• Rozszerzenia klas
• Fast enumeration
• współpraca z C++
![Page 17: Objective C](https://reader033.fdocuments.us/reader033/viewer/2022052412/558e133a1a28ab67128b47a6/html5/thumbnails/17.jpg)
Co dalej?
“The Objective-C 2.0 Programming Language”
http://developer.apple.com/
![Page 18: Objective C](https://reader033.fdocuments.us/reader033/viewer/2022052412/558e133a1a28ab67128b47a6/html5/thumbnails/18.jpg)
www.mackn.agh.edu.pl
![Page 19: Objective C](https://reader033.fdocuments.us/reader033/viewer/2022052412/558e133a1a28ab67128b47a6/html5/thumbnails/19.jpg)
Dziękuję za uwagę!