Your SlideShare is downloading. ×
0
ARCでめちゃモテiOSプログラマー
ARCでめちゃモテiOSプログラマー
ARCでめちゃモテiOSプログラマー
ARCでめちゃモテiOSプログラマー
ARCでめちゃモテiOSプログラマー
ARCでめちゃモテiOSプログラマー
ARCでめちゃモテiOSプログラマー
ARCでめちゃモテiOSプログラマー
ARCでめちゃモテiOSプログラマー
ARCでめちゃモテiOSプログラマー
ARCでめちゃモテiOSプログラマー
ARCでめちゃモテiOSプログラマー
ARCでめちゃモテiOSプログラマー
ARCでめちゃモテiOSプログラマー
ARCでめちゃモテiOSプログラマー
ARCでめちゃモテiOSプログラマー
ARCでめちゃモテiOSプログラマー
ARCでめちゃモテiOSプログラマー
ARCでめちゃモテiOSプログラマー
ARCでめちゃモテiOSプログラマー
ARCでめちゃモテiOSプログラマー
ARCでめちゃモテiOSプログラマー
ARCでめちゃモテiOSプログラマー
ARCでめちゃモテiOSプログラマー
ARCでめちゃモテiOSプログラマー
ARCでめちゃモテiOSプログラマー
ARCでめちゃモテiOSプログラマー
ARCでめちゃモテiOSプログラマー
ARCでめちゃモテiOSプログラマー
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

ARCでめちゃモテiOSプログラマー

15,696

Published on

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

No Downloads
Views
Total Views
15,696
On Slideshare
0
From Embeds
0
Number of Embeds
12
Actions
Shares
0
Downloads
66
Comments
0
Likes
26
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. ARC iOS (id:ninjinkun / @ninjinkun)
  • 2. • Cocoa Touch• ARC• ARC•• ARC•• Tips• GC
  • 3. Cocoa Touch • retain / relase -(void)setName:(NSString *)newName { name = [newName retain]; } -(void)dealloc { [name release]; [super dealloc]; 1 3 0 } • Ownership • Ownership retain • Ownership release • 0
  • 4. Cocoa TouchAutorelase • • autorelease • release • / •
  • 5. Cocoa TouchAutorelase • • autorelease • release • / • -(void)buildNewName { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSMutableArray *array = [[[NSMutableArray alloc] init] autorelease]; [array addObject:@"hoge"]; [array addObject:@"fuga"]; [array addObject:@"piyo"]; name =[array componentsJoinedByString:@","]; [pool drain]; }
  • 6. ARC• Automatic Reference Counting•• iOS 5 / Mac OS X 10.7
  • 7. ARC• •• (GC)• Static Analyzer
  • 8. ARC• @interface NonARCObject : NSObject { NSString *name; } -(id)initWithName:(NSString *)name; @end @implementation NonARCObject -(id)initWithName:(NSString *)newName { self = [super init]; if (self) { name = [newName retain]; } return self; } -(void)dealloc { [name release]; [super dealloc]; } @end
  • 9. ARC• @interface ARCObject : NSObject { NSString *name; } -(id)initWithName:(NSString *)name; @end @implementation ARCObject -(id)initWithName:(NSString *)newName { self = [super init]; if (self) { name = newName; } return self; } @end
  • 10. ARCARC • • … • • • •
  • 11. ARC __strong•• Ownership• • retain, release -(void)buildNewName { { __strong NSMutableArray *array = [[NSMutableArray alloc] init]; [array addObject:@"hoge"]; [array addObject:@"fuga"]; [array addObject:@"piyo"]; name =[array componentsJoinedByString:@","]; } } !
  • 12. ARC __strong• • retain, dealloc relase @interface ARCUser : NSObject { __strong NSString *name; } @end @implementation ARCUser -(id)initWithName:(NSString *)newName { self = [super init]; if (self) { name = newName; // [newName retain] } return self; } -(void)dealloc { // [name release] } @end
  • 13. ARC __weak• __weak • • Ownership • nil • • iOS 5 @interface ARCUser : NSObject { __weak id delegate; } @end
  • 14. ARC __unsafe_unretainded• • assign•• iOS 4.3 @interface ARCUser : NSObject { __unsafe_unretained id delegate; } @end
  • 15. ARC __autoreleasing• autorelase•• @autorelasepool { } -(NSArray *)comvertImageToJpeg:(NSArray *)files { NSMutableArray *dataStore = [NSMutableArray array]; @autoreleasepool { for (NSString *filePath in files) { __autoreleasing UIImage *image = [[UIImage alloc] initWithContentsOfFile:filePath]; NSData *data = UIImageJPEGRepresentation(image, 1.0); [dataStore addObject:data]; } } return [dataStore copy]; }
  • 16. ARC• retain, release, autorelase • retainCount• [super dealloc] • dealloc -(void)dealloc { delegate = nil; }• C __bridge NSString *str = @"hogehoge"; CFStringRef strRef = (__bridge CFStringRef)str; CFStringRef strRef = (__bridge_retained CFStringRef)str;
  • 17. • ARC __strong• __strong __strong __strong __strong __strong __strong
  • 18. • iOS 5 __weak• iOS 4.3 __unsafe_unretaind• nil __strong __weak __strong __strong __strong
  • 19. ARC•
  • 20. ARCretain / relase • -S • • _objc_release() • _objc_retain() • _objc_retainAutoreleasedReturnValue()
  • 21. ARC__weak • _objc_storeWeak() • 0 _objc_destroyWeak() • • nil • This document is licensed to ninjin@mac.com.
  • 22. Blocks • ARC • self ? • • release • BlocksKit UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; [button addEventHandler:^(id sender) { [self showPhotoPickerView]; } forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:button];
  • 23. Blocks • UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; __unsafe_unretained id _self = self; // !? [button addEventHandler:^(id sender) { [_self showPhotoPickerView]; } forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:button];
  • 24. Blocks • UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; __unsafe_unretained id _self = self; // !? [button addEventHandler:^(id sender) { !? [_self showPhotoPickerView]; } forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:button];
  • 25. TipsARC • -fno-objc-arc
  • 26. TipsARC • Static Library • Static Library • Workspace
  • 27. Tips • ARC • iOS 5 __weak • Blocks • UI • UI Blocks
  • 28. GC• GC • iOS •• • CPU
  • 29. • ARC• ( )• __weak• GC • • ( )• ARC

×