Objective-C Survives       Shumpei Akai
Objective-C• Objective-C == C + (Smalltalk    )OOP• C++ == C + Chaos
Objective-C•   C    •   Objective-C++•    •       Ruby    •                   OK•
•           3    •    •    ••       C
• Objective-C•               Cocoa
•    • gcc    • clang (LLVM          )•                   “.m”
•    • mac     XCode•    • Cocoa (mac) / Cocoa Touch (iOS)    • GNUStep (        )
Objective-C•   1983:          Brad Cox       (C++   )•   1988: NeXT (              )•   1995: NeXT•   1996: Apple    NeXT•...
•    //      [str length]    //      1      [array objectAtIndex:0]    //     2     [array insertObject: obj atIndex: 2]
•    • Ruby Lisp    • “insertObject:atIndex:”    • “objectAtIndex:”
•    • stringByAppendingString:•    • setObject:forKey:•
•    ••    •
id :
※    Objective-C
• ClassName*   OK •• id •
nil•               (id )    • null• nil • 0/NULL/nil •
NSMutableArray *array =[NSMutableArray arrayWithObjects: @"one",@"two”, nil];NSArray *newAdditions =[NSArray arrayWithObje...
BOOL•    • C++/C99•               YES/NO
•                  (.h)@interface ClassName : SuperClassName {  id instanceVariable;}- (void)instanceMethod;+ (id)classmet...
•           (.m)    @implementation ClassName    - (void)instanceMethod{      //    }    + (id)classmethod{      //    }  ...
•               (java.lang.Object      )    •    • Cocoa   NSObject    •
•   java    •    •                           2   prefix    •   apple   NS (== NeXT Step)    •
•   - (void)instanceMethodWithArg:(id)arg{ }    •                    Java    •             self        •
• obj->instanceVar •            (        ) • self• @public, @protected, @private • @protected               (     )
•   + (void)classMethodWithArg:(id)arg{ }    ••               [ClassName methodName]
•   [ClassName class]    •    •                   ==    •   [ClassName foo] == [[ClassName class] foo]
•    • static
•
+alloc        +allocWithZone:•    • Cocoa    •    •
- init    • [[NSObject alloc] init]       •       • init-(id) init{    self = [super init];    if(self){       //    }    ...
alloc   init•••                      ?    •    •
Cocoa•    •        • free           retain(+1)        •            release(-1)        •        0
•                           caller          •   alloc,new,copy,mutableCopy          •                                +1-(v...
•        •- (void)doBarWithArray:(NSArray*)ary{  id obj=[ary objectAtIndex:0];  //ary obj release}
retain•                    /        retain    •    - (void)doBarWithArray:(NSArray*)ary{      self->ary = [ary retain];    }
release•                       release    • nil    - (void)didReceiveMemoryWarning{      [self->data release];      self->...
•                caller          •   caller   free-(NSString*) makeString{  return [[NSString alloc] init] ;   //caller re...
autorelease      •           release          •                                             release          •            ...
AutoreleasePool    •   autorelease        •             =>                              release        •- (void)foo{   NSA...
dealloc•                        0    •                        obj        release-(void) dealloc{  [self->str release];  [s...
•    • Cocoa    •      •       retain      •       retain
• Java interface • optional                               OK @protocol HogeProtocol <SuperProtocol> -(BOOL)isCharactor; -(...
• Java • id<FooProtocol> : FooProtocol • BarClass<FooProtocol>* : BarClass    FooProtocol
•    @implementation ClassName(CategoryName)    - (void)addingMethod{      //    }    @end
•   obj.proptyName           •@interface ClassName : NSObject {}@property (nonatomic,retain) id prop;   @implementation Cl...
•   NSObject•                                 ?    •   - (BOOL)respondsToSelector:(SEL)aSelector•    •   - (id)performSele...
(cont.)•    • - (IMP)methodForSelector:(SEL)aSelector•    •   Class NSClassFromString(NSString *aClassName);
•    • NSString      •            @”hoge”;    • NSMutableString• Cocoa       mutable         immutable
• NSArray/NSMutableArray •                    :        •     [NSMutableArray arrayWithObjects:@”one”,              @”two”,...
/•    • NSDictionary/NSMutableDictionary•    • NSSet/NSMutableSet
•   NSValue    •   C•   NSNumber    •    •                  1        •   [NSNumber numberWithBool:YES]        •   [NSNumbe...
Objective-C•C••  •       C
Objective-C•           OOP    •
Objective-C• OS •   •   •          /
•• delegate• target/action• ARC(Automatic Reference Counting)• Blocks• Grand Central Dispatch
Objective-C Survives
Objective-C Survives
Objective-C Survives
Upcoming SlideShare
Loading in...5
×

Objective-C Survives

2,187

Published on

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
2,187
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
13
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
  • Transcript of "Objective-C Survives"

    1. 1. Objective-C Survives Shumpei Akai
    2. 2. Objective-C• Objective-C == C + (Smalltalk )OOP• C++ == C + Chaos
    3. 3. Objective-C• C • Objective-C++• • Ruby • OK•
    4. 4. • 3 • • •• C
    5. 5. • Objective-C• Cocoa
    6. 6. • • gcc • clang (LLVM )• “.m”
    7. 7. • • mac XCode• • Cocoa (mac) / Cocoa Touch (iOS) • GNUStep ( )
    8. 8. Objective-C• 1983: Brad Cox (C++ )• 1988: NeXT ( )• 1995: NeXT• 1996: Apple NeXT• 2001: Mac OS X• 2007: Objective-C 2.0
    9. 9. • // [str length] // 1 [array objectAtIndex:0] // 2 [array insertObject: obj atIndex: 2]
    10. 10. • • Ruby Lisp • “insertObject:atIndex:” • “objectAtIndex:”
    11. 11. • • stringByAppendingString:• • setObject:forKey:•
    12. 12. • •• •
    13. 13. id :
    14. 14. ※ Objective-C
    15. 15. • ClassName* OK •• id •
    16. 16. nil• (id ) • null• nil • 0/NULL/nil •
    17. 17. NSMutableArray *array =[NSMutableArray arrayWithObjects: @"one",@"two”, nil];NSArray *newAdditions =[NSArray arrayWithObjects: @"3", @"4", @"5",nil];[arry addObjectsFromArray: newAdditions];
    18. 18. BOOL• • C++/C99• YES/NO
    19. 19. • (.h)@interface ClassName : SuperClassName { id instanceVariable;}- (void)instanceMethod;+ (id)classmethod;@end
    20. 20. • (.m) @implementation ClassName - (void)instanceMethod{ // } + (id)classmethod{ // } @end
    21. 21. • (java.lang.Object ) • • Cocoa NSObject •
    22. 22. • java • • 2 prefix • apple NS (== NeXT Step) •
    23. 23. • - (void)instanceMethodWithArg:(id)arg{ } • Java • self •
    24. 24. • obj->instanceVar • ( ) • self• @public, @protected, @private • @protected ( )
    25. 25. • + (void)classMethodWithArg:(id)arg{ } •• [ClassName methodName]
    26. 26. • [ClassName class] • • == • [ClassName foo] == [[ClassName class] foo]
    27. 27. • • static
    28. 28.
    29. 29. +alloc +allocWithZone:• • Cocoa • •
    30. 30. - init • [[NSObject alloc] init] • • init-(id) init{ self = [super init]; if(self){ // } return self;}
    31. 31. alloc init••• ? • •
    32. 32. Cocoa• • • free retain(+1) • release(-1) • 0
    33. 33. • caller • alloc,new,copy,mutableCopy • +1-(void) doFoo{ NSString* str=[[NSString alloc] init] ; // [str release]; //}
    34. 34. • •- (void)doBarWithArray:(NSArray*)ary{ id obj=[ary objectAtIndex:0]; //ary obj release}
    35. 35. retain• / retain • - (void)doBarWithArray:(NSArray*)ary{ self->ary = [ary retain]; }
    36. 36. release• release • nil - (void)didReceiveMemoryWarning{ [self->data release]; self->data = nil; //data free }
    37. 37. • caller • caller free-(NSString*) makeString{ return [[NSString alloc] init] ; //caller release} -(NSString*) makeString{ return [[[NSString alloc] init] release]; //return }
    38. 38. autorelease • release • release • obj-(NSString*) makeString{ return [[[NSString alloc] init] autorelease]; //}
    39. 39. AutoreleasePool • autorelease • => release •- (void)foo{ NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; //do something [pool release];}
    40. 40. dealloc• 0 • obj release-(void) dealloc{ [self->str release]; [self->ary release]; [super dealloc];}
    41. 41. • • Cocoa • • retain • retain
    42. 42. • Java interface • optional OK @protocol HogeProtocol <SuperProtocol> -(BOOL)isCharactor; -(BOOL)isDisplay; -(void)start; -(void)abort; -(BOOL)step; @optional -(void)callbackWithData:(NSData*)data; @end
    43. 43. • Java • id<FooProtocol> : FooProtocol • BarClass<FooProtocol>* : BarClass FooProtocol
    44. 44. • @implementation ClassName(CategoryName) - (void)addingMethod{ // } @end
    45. 45. • obj.proptyName •@interface ClassName : NSObject {}@property (nonatomic,retain) id prop; @implementation ClassName@end @synthesize prop; @end
    46. 46. • NSObject• ? • - (BOOL)respondsToSelector:(SEL)aSelector• • - (id)performSelector:(SEL)aSelector • - (id)performSelector:(SEL)aSelector withObject:(id)anObject • - (id)performSelector:(SEL)aSelector withObject:(id)anObject withObject:(id)anotherObject
    47. 47. (cont.)• • - (IMP)methodForSelector:(SEL)aSelector• • Class NSClassFromString(NSString *aClassName);
    48. 48. • • NSString • @”hoge”; • NSMutableString• Cocoa mutable immutable
    49. 49. • NSArray/NSMutableArray • : • [NSMutableArray arrayWithObjects:@”one”, @”two”,nil]• Cocoa • nil
    50. 50. /• • NSDictionary/NSMutableDictionary• • NSSet/NSMutableSet
    51. 51. • NSValue • C• NSNumber • • 1 • [NSNumber numberWithBool:YES] • [NSNumber numberWithInt:0] • [NSNumber numberWithDouble:1.0]
    52. 52. Objective-C•C•• • C
    53. 53. Objective-C• OOP •
    54. 54. Objective-C• OS • • • /
    55. 55. •• delegate• target/action• ARC(Automatic Reference Counting)• Blocks• Grand Central Dispatch
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×