連邦の白いヤツ 「Objective-C」
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

連邦の白いヤツ 「Objective-C」

on

  • 929 views

6/18社内勉強会の資料。

6/18社内勉強会の資料。

Statistics

Views

Total Views
929
Views on SlideShare
928
Embed Views
1

Actions

Likes
0
Downloads
3
Comments
0

1 Embed 1

http://slideclip.b-prep.com 1

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n

連邦の白いヤツ 「Objective-C」 Presentation Transcript

  • 1. "initialize aMyObject "aMyObject initialize." 30 setSize aSquare "aSquare setSize : 30." + 4 "total := 3 + 4.min: other ^self < other ifTrue: [self] ifFalse: [other].
  • 2. //[receiver msg];// msg:with:val = [receiver msg: arg1 with: arg2];
  • 3. //[receiver msg];// msg:with:val = [receiver msg: arg1 with: arg2];
  • 4. #import <Foundation/Foundation.h>//@interface MyClass : NSObject { int val;}- (id)init;+ (void)classMethod:(id)arg; //- (id)method:(NSObject*)arg1 with:(int)arg2;- (id)method:(NSObject*)arg1 param:(int)arg2;@end//@implementation MyClass+ (void)classMethod:(id)arg { // some operation}- (id)method:(NSObject*)arg1 with:(int)args2 { return obj;}- (id)method:(NSObject*)arg1 param:(int)args2 { return obj;}@end
  • 5. #import <Foundation/Foundation.h>//@interface MyClass : NSObject { int val;}- (id)init;+ (void)classMethod:(id)arg; //- (id)method:(NSObject*)arg1 with:(int)arg2;- (id)method:(NSObject*)arg1 param:(int)arg2;@end//@implementation MyClass+ (void)classMethod:(id)arg { // some operation}- (id)method:(NSObject*)arg1 with:(int)args2 { return obj;}- (id)method:(NSObject*)arg1 param:(int)args2 { return obj;}@end
  • 6. //[MyClass classMethod:arg];id obj = [[MyClass alloc]init];// MyClass* obj = [[MyClass alloc]init];// method:with:[obj method :arg with:10];
  • 7. // init- (id)init { self = [super init]; // if(self != nil) { val = 1; obj = [[SomeClass alloc] init]; } return self;}
  • 8. AlarmFake* f = [[AlarmFake alloc]init];if( [f conformsToProtocol:@protocol(Alarm)] ){ //}
  • 9. @interface ObjcClass : NSObject{@private int x_;@protected // int y_;@public int z_;@package // int w_;}@end
  • 10. ObjcClass* oc = [[ObjcClass alloc]init]; int z = oc->z_; // public int x = oc->x_; //
  • 11. ObjcClass* oc = [[ObjcClass alloc]init]; int z = oc->z_; // public int x = oc->x_; //
  • 12. @interface ObjcClass : NSObject- (void)print;@end@implementation ObjcClass- (void)print { NSLog(@"ObjcClass print:");}- (void)private_print { NSLog(@"ObjcClass private_print:");}@endvoid test() { ObjcClass* oc = [[ObjcClass alloc]init]; [oc print]; // ObjcClass print: [oc private_print]; // ObjcClass private_print:
  • 13. @interface ObjcClass : NSObject- (void)print;@end@implementation ObjcClass- (void)print { NSLog(@"ObjcClass print:");}- (void)private_print { NSLog(@"ObjcClass private_print:");}@endvoid test() { ObjcClass* oc = [[ObjcClass alloc]init]; [oc print]; // ObjcClass print: [oc private_print]; // ObjcClass private_print:
  • 14. #include <boost/shared_ptr.hpp>class CppClass{public: CppClass(){} void print() const { std::cout << "CppClass::print" << std::endl; }};@interface ObjcClass : NSObject- (void)print;@end@implementation ObjcClass- (void)print { NSLog(@"ObjcClass print");}@endvoid boost_test(){ boost::shared_ptr<CppClass> p(new CppClass); ObjcClass* oc = [[ObjcClass alloc]init]; [oc print]; // ObjcClass print p->print(); // CppClass::print}
  • 15. MyObject* obj = [[MyObject alloc] init];[obj method :arg with:10];[nil method :arg with:10]; //
  • 16. MyObject* obj = [[MyObject alloc] init]; //[obj retain]; //NSLog(@"count=%d", [obj retainCount] ); // count=2[obj release] ; //[obj release] ; ////MyObject* obj = [[[MyObject alloc] init] autorelease];[obj retain]; //
  • 17. - (BOOL)respondsToSelector:(SEL)aSelector;MySubClass* obj = [[MySubClass alloc] init];if( [obj respondsToSelector:@selector(init)] ){ NSLog(@"YES");}
  • 18. - (BOOL)respondsToSelector:(SEL)aSelector;MySubClass* obj = [[MySubClass alloc] init];if( [obj respondsToSelector:@selector(init)] ){ NSLog(@"YES");}
  • 19. @interface NSObject <NSObject> { Class isa;}- (id)init;+ (id)alloc;- (void)dealloc;- (id)copy;+ (Class)superclass;+ (Class)class;- (IMP)methodForSelector:(SEL)aSelector;+ (NSString *)description;+ (BOOL)isSubclassOfClass:(Class)aClass@end
  • 20. - (BOOL)isEqual:(id)object;- (NSUInteger)hash;- (Class)superclass;- (Class)class;- (id)self;- (BOOL)isKindOfClass:(Class)aClass;- (BOOL)isMemberOfClass:(Class)aClass;- (BOOL)conformsToProtocol:(Protocol *)aProtocol;- (BOOL)respondsToSelector:(SEL)aSelector;- (id)retain;- (oneway void)release;- (id)autorelease;- (NSUInteger)retainCount;
  • 21. Class meta = [MySubClass class]; // MySubClassClass metameta = [meta class];if( [meta isKindOfClass:[NSObject class]] ){ NSLog(@"YES");}
  • 22. NSBundle* mainBundle = [NSBundle mainBundle];NSBundle* moduleBundle = [mainBundle bundleWithPath : @"path"];NSString* loadbleClassName =Class c = [moduleBundle classNamed : loadbleClassName ];id = [[c alloc] init] autorelease];
  • 23. @interface MySubClass : MyObject { int x_;}@property int x_;@end@implementation MySubClass-(int)x_{ return x_;} // getter-(void)setX_:(int)x { x_ = x;} // setter@end MySubClass* obj = [[MySubClass alloc] init]; int xx= p.x_; p.x_ = 200;
  • 24. @interface MySubClass : MyObject { int x_;}@property int x_;@end@implementation MySubClass-(int)x_{ return x_;} // getter-(void)setX_:(int)x { x_ = x;} // setter@end MySubClass* obj = [[MySubClass alloc] init]; int xx= p.x_; p.x_ = 200;
  • 25. @interface MySubClass : MyObject { int y_;}@property int y_;@end@implementation MySubClass@synthesize y_;@end int yy= p.y_; p.y_ = 200;
  • 26. @interface MySubClass : MyObject { int y_;}@property int y_;@end@implementation MySubClass@synthesize y_;@end int yy= p.y_; p.y_ = 200;
  • 27. @protocol AlarmReq-(void)nowTime;@end// “<>”@interface MyClockReq : NSObject<AlarmReq>-(void)nowTime;@end@implementation MyClockReq-(void)nowTime{}@end
  • 28. @protocol AlarmReq-(void)nowTime;@end// “<>”@interface MyClockReq : NSObject<AlarmReq>-(void)nowTime;@end@implementation MyClockReq-(void)nowTime{}@end
  • 29. AlarmFake* f = [[AlarmFake alloc]init]; id<Alarm> f2 = f; if( [f2 conformsToProtocol:@protocol(Alarm)] ) { // }
  • 30. AlarmFake* f = [[AlarmFake alloc]init]; id<Alarm> f2 = f; if( [f2 conformsToProtocol:@protocol(Alarm)] ) { // }
  • 31. @protocol Alarm -(void)nowTime;@optional -(void)snooze;@end@interface MyClock : NSObject<Alarm>-(void)nowTime;//-(void)snooze;@end
  • 32. @protocol Alarm -(void)nowTime;@optional -(void)snooze;@end//-(void)snooze@interface MyClock : NSObject<Alarm>-(void)nowTime;@end@implementation MyClock-(void)nowTime { NSLog(@"nowTime"); }@endMyClock* a = [[MyClock alloc]init];[a nowTime];[a snooze]; //
  • 33. @protocol Alarm -(void)nowTime;@optional -(void)snooze;@end//-(void)snooze@interface MyClock : NSObject<Alarm>-(void)nowTime;@end@implementation MyClock-(void)nowTime { NSLog(@"nowTime"); }@endMyClock* a = [[MyClock alloc]init];[a nowTime];[a snooze]; //
  • 34. @interface MyObject : NSObject { int val;}- (void)bar;@end@implementation MyObject@end@interface MyObject(EventHandler)- (void)buttonClicked;@end@implementation MyObject(EventHandler)- (void)buttonClicked{ NSLog(@"calll buttonClicked");}@endvoid category_test(){ MyObject* obj = [[MyObject alloc]init]; [obj buttonClicked]; // call buttonClicked}
  • 35. @interface NSString(matuura)- (void)whatsName;@end@implementation NSString(matuura)- (void)whatsName{ NSLog(@"akihiko matuura");}@endvoid category_test(){ NSString* s = [[NSString alloc]init]; [s whatsName]; // akihiko matuura}
  • 36. @try{ if( ){ // errorcode = 1000; [NSException raise : @"Fatal Error occured" format : @"%d", errorcode]; // @throw [[MyException alloc]init]; }}@catch( NSException* ex ){ NSLog(@"name=%@, reason=%@",[ex name], [ex reason]); [ex raise]; // @throw; //}@catch( ... ){ NSLog(@"unknown exception");}@finaly{}
  • 37. @try{ if( ){ // errorcode = 1000; [NSException raise : @"Fatal Error occured" format : @"%d", errorcode]; // @throw [[MyException alloc]init]; }}@catch( NSException* ex ){ NSLog(@"name=%@, reason=%@",[ex name], [ex reason]); [ex raise]; // @throw; //}@catch( ... ){ NSLog(@"unknown exception");}@finaly{}
  • 38. void blocks_caller( void (^f)(void) ) { f(); }void blocks_test(){ blocks_caller( ^(){ NSLog(@"test1");} ); blocks_caller( ^(){ NSLog(@"test2");} );}
  • 39. Func<int, Func<int, int>> f = x => y => x + y;Func<int, int> fc = f(1);int x = fc(3); // 1 + 3function< function<int(int)> (int) > f = [] (int x){ return [x](int y){ return x+y;}; };auto fc = f(1);int x = fc(3); // 1 + 3
  • 40. void blocks_test(){ typedef int (^add_function)(int); add_function (^f)(int) = ^(int x){ return Block_copy(^(int y){ return x+y;}); }; add_function fc = f(1); NSLog(@"blocks_test() fc=%d", fc(3)); Block_release(fc);}
  • 41. for (NSString *element in array) { }