"initialize             aMyObject        "aMyObject initialize."    30       setSize          aSquare        "aSquare setS...
//[receiver msg];//                        msg:with:val = [receiver msg: arg1 with: arg2];
//[receiver msg];//                        msg:with:val = [receiver msg: arg1 with: arg2];
#import <Foundation/Foundation.h>//@interface MyClass : NSObject {   int val;}- (id)init;+ (void)classMethod:(id)arg; //- ...
#import <Foundation/Foundation.h>//@interface MyClass : NSObject {   int val;}- (id)init;+ (void)classMethod:(id)arg; //- ...
//[MyClass classMethod:arg];id obj = [[MyClass alloc]init];// MyClass* obj = [[MyClass alloc]init];// method:with:[obj met...
//            init- (id)init {   self = [super init]; //     if(self != nil) {         val = 1;         obj = [[SomeClass ...
AlarmFake* f = [[AlarmFake alloc]init];if( [f conformsToProtocol:@protocol(Alarm)] ){ //}
@interface ObjcClass : NSObject{@private int x_;@protected // int y_;@public int z_;@package // int w_;}@end
ObjcClass* oc = [[ObjcClass alloc]init]; int z = oc->z_; // public int x = oc->x_; //
ObjcClass* oc = [[ObjcClass alloc]init]; int z = oc->z_; // public int x = oc->x_; //
@interface ObjcClass : NSObject- (void)print;@end@implementation ObjcClass- (void)print { NSLog(@"ObjcClass print:");}- (v...
@interface ObjcClass : NSObject- (void)print;@end@implementation ObjcClass- (void)print { NSLog(@"ObjcClass print:");}- (v...
#include <boost/shared_ptr.hpp>class CppClass{public: CppClass(){} void print() const {     std::cout << "CppClass::print"...
MyObject* obj = [[MyObject alloc] init];[obj method :arg with:10];[nil method :arg with:10]; //
MyObject* obj = [[MyObject alloc] init]; //[obj retain]; //NSLog(@"count=%d", [obj retainCount] ); // count=2[obj release]...
- (BOOL)respondsToSelector:(SEL)aSelector;MySubClass* obj = [[MySubClass alloc] init];if( [obj respondsToSelector:@selecto...
- (BOOL)respondsToSelector:(SEL)aSelector;MySubClass* obj = [[MySubClass alloc] init];if( [obj respondsToSelector:@selecto...
@interface NSObject <NSObject> {  Class isa;}- (id)init;+ (id)alloc;- (void)dealloc;- (id)copy;+ (Class)superclass;+ (Clas...
- (BOOL)isEqual:(id)object;- (NSUInteger)hash;- (Class)superclass;- (Class)class;- (id)self;-   (BOOL)isKindOfClass:(Class...
Class meta = [MySubClass class]; // MySubClassClass metameta = [meta class];if( [meta isKindOfClass:[NSObject class]] ){  ...
NSBundle* mainBundle = [NSBundle mainBundle];NSBundle* moduleBundle = [mainBundle bundleWithPath : @"path"];NSString* load...
@interface MySubClass : MyObject {  int x_;}@property int x_;@end@implementation MySubClass-(int)x_{ return x_;}      // g...
@interface MySubClass : MyObject {  int x_;}@property int x_;@end@implementation MySubClass-(int)x_{ return x_;}      // g...
@interface MySubClass : MyObject {  int y_;}@property int y_;@end@implementation MySubClass@synthesize y_;@end  int yy= p....
@interface MySubClass : MyObject {  int y_;}@property int y_;@end@implementation MySubClass@synthesize y_;@end  int yy= p....
@protocol AlarmReq-(void)nowTime;@end//               “<>”@interface MyClockReq : NSObject<AlarmReq>-(void)nowTime;@end@im...
@protocol AlarmReq-(void)nowTime;@end//               “<>”@interface MyClockReq : NSObject<AlarmReq>-(void)nowTime;@end@im...
AlarmFake* f = [[AlarmFake alloc]init]; id<Alarm> f2 = f; if( [f2 conformsToProtocol:@protocol(Alarm)] ) {      // }
AlarmFake* f = [[AlarmFake alloc]init]; id<Alarm> f2 = f; if( [f2 conformsToProtocol:@protocol(Alarm)] ) {      // }
@protocol Alarm  -(void)nowTime;@optional  -(void)snooze;@end@interface MyClock : NSObject<Alarm>-(void)nowTime;//-(void)s...
@protocol Alarm  -(void)nowTime;@optional  -(void)snooze;@end//-(void)snooze@interface MyClock : NSObject<Alarm>-(void)now...
@protocol Alarm  -(void)nowTime;@optional  -(void)snooze;@end//-(void)snooze@interface MyClock : NSObject<Alarm>-(void)now...
@interface MyObject : NSObject {   int val;}- (void)bar;@end@implementation MyObject@end@interface MyObject(EventHandler)-...
@interface NSString(matuura)- (void)whatsName;@end@implementation NSString(matuura)- (void)whatsName{   NSLog(@"akihiko ma...
@try{    if(                   ){         //             errorcode = 1000;             [NSException raise : @"Fatal Error ...
@try{    if(                   ){         //             errorcode = 1000;             [NSException raise : @"Fatal Error ...
void blocks_caller( void (^f)(void) ) {  f(); }void blocks_test(){ blocks_caller( ^(){ NSLog(@"test1");} ); blocks_caller(...
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)>...
void blocks_test(){ typedef int (^add_function)(int); add_function (^f)(int) =             ^(int x){              return B...
for (NSString *element in array) {   }
連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」
Upcoming SlideShare
Loading in …5
×

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

918 views

Published on

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

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
918
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
6
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • \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」

    1. 1. "initialize aMyObject "aMyObject initialize." 30 setSize aSquare "aSquare setSize : 30." + 4 "total := 3 + 4.min: other ^self < other ifTrue: [self] ifFalse: [other].
    2. 2. //[receiver msg];// msg:with:val = [receiver msg: arg1 with: arg2];
    3. 3. //[receiver msg];// msg:with:val = [receiver msg: arg1 with: arg2];
    4. 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. 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. 6. //[MyClass classMethod:arg];id obj = [[MyClass alloc]init];// MyClass* obj = [[MyClass alloc]init];// method:with:[obj method :arg with:10];
    7. 7. // init- (id)init { self = [super init]; // if(self != nil) { val = 1; obj = [[SomeClass alloc] init]; } return self;}
    8. 8. AlarmFake* f = [[AlarmFake alloc]init];if( [f conformsToProtocol:@protocol(Alarm)] ){ //}
    9. 9. @interface ObjcClass : NSObject{@private int x_;@protected // int y_;@public int z_;@package // int w_;}@end
    10. 10. ObjcClass* oc = [[ObjcClass alloc]init]; int z = oc->z_; // public int x = oc->x_; //
    11. 11. ObjcClass* oc = [[ObjcClass alloc]init]; int z = oc->z_; // public int x = oc->x_; //
    12. 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. 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. 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. 15. MyObject* obj = [[MyObject alloc] init];[obj method :arg with:10];[nil method :arg with:10]; //
    16. 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. 17. - (BOOL)respondsToSelector:(SEL)aSelector;MySubClass* obj = [[MySubClass alloc] init];if( [obj respondsToSelector:@selector(init)] ){ NSLog(@"YES");}
    18. 18. - (BOOL)respondsToSelector:(SEL)aSelector;MySubClass* obj = [[MySubClass alloc] init];if( [obj respondsToSelector:@selector(init)] ){ NSLog(@"YES");}
    19. 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. 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. 21. Class meta = [MySubClass class]; // MySubClassClass metameta = [meta class];if( [meta isKindOfClass:[NSObject class]] ){ NSLog(@"YES");}
    22. 22. NSBundle* mainBundle = [NSBundle mainBundle];NSBundle* moduleBundle = [mainBundle bundleWithPath : @"path"];NSString* loadbleClassName =Class c = [moduleBundle classNamed : loadbleClassName ];id = [[c alloc] init] autorelease];
    23. 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. 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. 25. @interface MySubClass : MyObject { int y_;}@property int y_;@end@implementation MySubClass@synthesize y_;@end int yy= p.y_; p.y_ = 200;
    26. 26. @interface MySubClass : MyObject { int y_;}@property int y_;@end@implementation MySubClass@synthesize y_;@end int yy= p.y_; p.y_ = 200;
    27. 27. @protocol AlarmReq-(void)nowTime;@end// “<>”@interface MyClockReq : NSObject<AlarmReq>-(void)nowTime;@end@implementation MyClockReq-(void)nowTime{}@end
    28. 28. @protocol AlarmReq-(void)nowTime;@end// “<>”@interface MyClockReq : NSObject<AlarmReq>-(void)nowTime;@end@implementation MyClockReq-(void)nowTime{}@end
    29. 29. AlarmFake* f = [[AlarmFake alloc]init]; id<Alarm> f2 = f; if( [f2 conformsToProtocol:@protocol(Alarm)] ) { // }
    30. 30. AlarmFake* f = [[AlarmFake alloc]init]; id<Alarm> f2 = f; if( [f2 conformsToProtocol:@protocol(Alarm)] ) { // }
    31. 31. @protocol Alarm -(void)nowTime;@optional -(void)snooze;@end@interface MyClock : NSObject<Alarm>-(void)nowTime;//-(void)snooze;@end
    32. 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. 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. 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. 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. 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. 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. 38. void blocks_caller( void (^f)(void) ) { f(); }void blocks_test(){ blocks_caller( ^(){ NSLog(@"test1");} ); blocks_caller( ^(){ NSLog(@"test2");} );}
    39. 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. 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. 41. for (NSString *element in array) { }

    ×