Webエンジニアから見たiOS5

3,049 views
2,947 views

Published on

JavaScript化するObjective-Cについて

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

No Downloads
Views
Total views
3,049
On SlideShare
0
From Embeds
0
Number of Embeds
478
Actions
Shares
0
Downloads
8
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

Webエンジニアから見たiOS5

  1. 1. Web iOS 5 (id:ninjinkun / @ninjinkun)
  2. 2. Cocoa • 10 • Next Step, Mac OSX • • >< •
  3. 3. iOS • iOS • • SDK • • Apple • Web
  4. 4. • iOS• iOS 4, iOS 5
  5. 5. • Objective-C JavaScript ! • iOS 5
  6. 6. • (Blocks) JavaScript• (GCD)• (ARC)
  7. 7. (Blocks) JavaScript• JavaScript • Ajax API function sendRequest (url) { var req = new XMLHttpRequest(); // req.onreadystatechange = function(){ if (req.readyState == 4) { if (req.status == 200) { console.log("success"); } } }; req.open("GET", url); req.send(); }
  8. 8. (Blocks) Objective-C• iOS 4 Objective-C@interface Downloader : NSObject { NSURLConnection *conn;}@end@implementation Downloader- (void)sentRequest:(NSURL *)url { NSURLRequest *req = [NSURLRequest requestWithURL:url]; // conn = [NSURLConnection connectionWithRequest:req delegate:self];}- (void)connection:( NSURLConnection *) connection didReceiveResponse:( NSURLResponse *) response { // delegate NSLog(@"success");}@end
  9. 9. (Blocks) Objective-C• iOS 4 Objective-C@interface Downloader : NSObject { NSURLConnection *conn;}@end@implementation Downloader- (void)sentRequest:(NSURL *)url { NSURLRequest *req = [NSURLRequest requestWithURL:url]; // conn = [NSURLConnection connectionWithRequest:req delegate:self];}- (void)connection:( NSURLConnection *) connection didReceiveResponse:( NSURLResponse *) response { // delegate NSLog(@"success");}@end
  10. 10. (Blocks)iOS 4 • (Blocks) • • SDK Blocks • void(^hogeHandler)(NSArray *) = ^(NSArray *array){ NSLog(@"hoge"); };
  11. 11. (Blocks)@interface Downloader : NSObject { NSOperationQueue *queue;}@end@implementation Downloader- (void)sendRequest { queue = [[NSOperationQueue alloc] init]; NSURLRequest *req = [NSURLRequest requestWithURL:[NSURLURLWithString:@"http://www.apple.com/"]]; // [NSURLConnection sendAsynchronousRequest:req queue:queuecompletionHandler:^(NSURLResponse *res, NSData *data, NSError *err) { if ([(NSHTTPURLResponse *)res statusCode] == 200) { // NSLog(@"success"); } }];}@end
  12. 12. (Blocks)@interface Downloader : NSObject { NSOperationQueue *queue;}@end@implementation Downloader- (void)sendRequest { queue = [[NSOperationQueue alloc] init]; NSURLRequest *req = [NSURLRequest requestWithURL:[NSURLURLWithString:@"http://www.apple.com/"]]; // [NSURLConnection sendAsynchronousRequest:req queue:queuecompletionHandler:^(NSURLResponse *res, NSData *data, NSError *err) { if ([(NSHTTPURLResponse *)res statusCode] == 200) { // NSLog(@"success"); } }];}@end !
  13. 13. (GCD)JavaScript • JavaScript • • • • iOS • • •
  14. 14. (GCD)iOS 4 • @interface FileReader : NSObject { NSString *fileContent; } @property (nonatomic, assign) id delegate; @end @implementation FileReader -(void)readFile:(NSString *)filename { [self performSelectorInBackground:@selector(readFileOnBackground:) withObject:filename]; } // -(void)readFileOnBackground:(NSString *)filename { NSError *err = nil; fileContent = [NSString stringWithContentsOfFile:filename encoding:NSUTF8StringEncoding error:&err]; // UI [delegate performSelectorOnMainThread:@selector(updateViewWithFile:) withObject:fileContent waitUntilDone:NO]; } @end
  15. 15. (GCD)iOS 4 • Grand Central Dispatch • • • • •
  16. 16. (GCD)iOS 4 •@interface FileReader : NSObject@property (nonatomic, assign) id delegate;@end@implementation FileReader-(void)readFile:(NSString *)filename { // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0),^{ NSError *err = nil; NSString *fileContent = [NSString stringWithContentsOfFile:filenameencoding:NSUTF8StringEncoding error:&err]; // dispatch_async(dispatch_get_main_queue(), ^{ [delegate updateViewWithFile:fileContent]; }); });}@end
  17. 17. (ARC)JavaScript • GC • • Web
  18. 18. (ARC)iOS 5 •@interface User : NSObject { NSString *name; NSString *imageUrl;}@end@implementation User-(id)initWithDictionary:(NSDictionary *)dict { self = [super init]; if (self) { name = [[dict objectForKey:@"name"] retain]; // imageUrl = [[dict objectForKey:@"image_url"] retain]; } return self;}//-(void)dealloc { [name release]; [imageUrl release]; [super dealloc];}@end
  19. 19. (ARC)iOS 5 •@interface User : NSObject { NSString *name; NSString *imageUrl;}@end@implementation User-(id)initWithDictionary:(NSDictionary *)dict { self = [super init]; if (self) { name = [[dict objectForKey:@"name"] retain]; // imageUrl = [[dict objectForKey:@"image_url"] retain]; } return self;}//-(void)dealloc { [name release]; [imageUrl release]; [super dealloc];}@end
  20. 20. (ARC)iOS 5 • Automatic Reference Counting • • • •
  21. 21. (ARC)iOS 5 • ! @interface User : NSObject { NSString *name; NSString *imageUrl; } @end @implementation User -(id)initWithDictionary:(NSDictionary *)dict { self = [super init]; if (self) { name = [dict objectForKey:@"name"]; imageUrl = [dict objectForKey:@"image_url"]; } return self; } // @end
  22. 22. GC• GC • iOS •• • CPU
  23. 23. • Objective-C JavaScript ! • … …• Objective-C •• iOS •

×