Objective-C Survives
Upcoming SlideShare
Loading in...5
×
 

Objective-C Survives

on

  • 1,460 views

 

Statistics

Views

Total Views
1,460
Slideshare-icon Views on SlideShare
1,460
Embed Views
0

Actions

Likes
0
Downloads
12
Comments
0

0 Embeds 0

No embeds

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

Objective-C Survives Objective-C Survives Presentation Transcript

  • 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• 2001: Mac OS X• 2007: Objective-C 2.0
  • • // [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 arrayWithObjects: @"3", @"4", @"5",nil];[arry addObjectsFromArray: newAdditions];
  • BOOL• • C++/C99• YES/NO
  • • (.h)@interface ClassName : SuperClassName { id instanceVariable;}- (void)instanceMethod;+ (id)classmethod;@end
  • • (.m) @implementation ClassName - (void)instanceMethod{ // } + (id)classmethod{ // } @end
  • • (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){ // } return self;}
  • alloc init••• ? • •
  • Cocoa• • • free retain(+1) • release(-1) • 0
  • • caller • alloc,new,copy,mutableCopy • +1-(void) doFoo{ NSString* str=[[NSString alloc] init] ; // [str release]; //}
  • • •- (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->data = nil; //data free }
  • • caller • caller free-(NSString*) makeString{ return [[NSString alloc] init] ; //caller release} -(NSString*) makeString{ return [[[NSString alloc] init] release]; //return }
  • autorelease • release • release • obj-(NSString*) makeString{ return [[[NSString alloc] init] autorelease]; //}
  • AutoreleasePool • autorelease • => release •- (void)foo{ NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; //do something [pool release];}
  • dealloc• 0 • obj release-(void) dealloc{ [self->str release]; [self->ary release]; [super dealloc];}
  • • • Cocoa • • retain • retain
  • • Java interface • optional OK @protocol HogeProtocol <SuperProtocol> -(BOOL)isCharactor; -(BOOL)isDisplay; -(void)start; -(void)abort; -(BOOL)step; @optional -(void)callbackWithData:(NSData*)data; @end
  • • 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 ClassName@end @synthesize prop; @end
  • • 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
  • (cont.)• • - (IMP)methodForSelector:(SEL)aSelector• • Class NSClassFromString(NSString *aClassName);
  • • • NSString • @”hoge”; • NSMutableString• Cocoa mutable immutable
  • • NSArray/NSMutableArray • : • [NSMutableArray arrayWithObjects:@”one”, @”two”,nil]• Cocoa • nil
  • /• • NSDictionary/NSMutableDictionary• • NSSet/NSMutableSet
  • • NSValue • C• NSNumber • • 1 • [NSNumber numberWithBool:YES] • [NSNumber numberWithInt:0] • [NSNumber numberWithDouble:1.0]
  • Objective-C•C•• • C
  • Objective-C• OOP •
  • Objective-C• OS • • • /
  • •• delegate• target/action• ARC(Automatic Reference Counting)• Blocks• Grand Central Dispatch