ひろ子 in objective-c
DESCRIPTION
TRANSCRIPT
![Page 1: ひろ子 in Objective-C](https://reader034.vdocuments.net/reader034/viewer/2022052315/53fdc9608d7f72a81c8b4b16/html5/thumbnails/1.jpg)
![Page 2: ひろ子 in Objective-C](https://reader034.vdocuments.net/reader034/viewer/2022052315/53fdc9608d7f72a81c8b4b16/html5/thumbnails/2.jpg)
who is ひろ子 ?
![Page 3: ひろ子 in Objective-C](https://reader034.vdocuments.net/reader034/viewer/2022052315/53fdc9608d7f72a81c8b4b16/html5/thumbnails/3.jpg)
![Page 4: ひろ子 in Objective-C](https://reader034.vdocuments.net/reader034/viewer/2022052315/53fdc9608d7f72a81c8b4b16/html5/thumbnails/4.jpg)
![Page 5: ひろ子 in Objective-C](https://reader034.vdocuments.net/reader034/viewer/2022052315/53fdc9608d7f72a81c8b4b16/html5/thumbnails/5.jpg)
void hiroko(int height) { if(height < 180) height = 180; }
正しくない hiroko の実装
![Page 6: ひろ子 in Objective-C](https://reader034.vdocuments.net/reader034/viewer/2022052315/53fdc9608d7f72a81c8b4b16/html5/thumbnails/6.jpg)
void hiroko(int *height) { if(*height < 180) *height = 180; }
正しい hiroko の実装(多分
![Page 7: ひろ子 in Objective-C](https://reader034.vdocuments.net/reader034/viewer/2022052315/53fdc9608d7f72a81c8b4b16/html5/thumbnails/7.jpg)
int h1 = 195; hiroko(&h1); NSLog(@"h1: %d", h1);
![Page 8: ひろ子 in Objective-C](https://reader034.vdocuments.net/reader034/viewer/2022052315/53fdc9608d7f72a81c8b4b16/html5/thumbnails/8.jpg)
int h1 = 195; hiroko(&h1); NSLog(@"h1: %d", h1);
2014-05-09 14:09:40.299 Hiroko[23593:60b] h1: 195
理想通りなのでOK
![Page 9: ひろ子 in Objective-C](https://reader034.vdocuments.net/reader034/viewer/2022052315/53fdc9608d7f72a81c8b4b16/html5/thumbnails/9.jpg)
int h1 = 195; hiroko(&h1); NSLog(@"h1: %d", h1);
2014-05-09 14:09:40.299 Hiroko[23593:60b] h1: 195
int h2 = 175; hiroko(&h2); NSLog(@"h2: %d", h2);
![Page 10: ひろ子 in Objective-C](https://reader034.vdocuments.net/reader034/viewer/2022052315/53fdc9608d7f72a81c8b4b16/html5/thumbnails/10.jpg)
int h1 = 195; hiroko(&h1); NSLog(@"h1: %d", h1);
2014-05-09 14:09:40.301 Hiroko[23593:60b] h2: 180
2014-05-09 14:09:40.299 Hiroko[23593:60b] h1: 195
int h2 = 175; hiroko(&h2); NSLog(@"h2: %d", h2);
ちゃんと超能力が働いてる
![Page 11: ひろ子 in Objective-C](https://reader034.vdocuments.net/reader034/viewer/2022052315/53fdc9608d7f72a81c8b4b16/html5/thumbnails/11.jpg)
解説
int h = 175; !int *p; p = &h; *p = 180; !NSLog(@"h: %d", h);
![Page 12: ひろ子 in Objective-C](https://reader034.vdocuments.net/reader034/viewer/2022052315/53fdc9608d7f72a81c8b4b16/html5/thumbnails/12.jpg)
解説
int h = 175; !int *p; p = &h; *p = 180; !NSLog(@"h: %d", h);
175
h: 0xbfffca44
![Page 13: ひろ子 in Objective-C](https://reader034.vdocuments.net/reader034/viewer/2022052315/53fdc9608d7f72a81c8b4b16/html5/thumbnails/13.jpg)
解説
int h = 175; !int *p; p = &h; *p = 180; !NSLog(@"h: %d", h);
175
h: 0xbfffca44
NULL
p: 0xbfffca40
![Page 14: ひろ子 in Objective-C](https://reader034.vdocuments.net/reader034/viewer/2022052315/53fdc9608d7f72a81c8b4b16/html5/thumbnails/14.jpg)
解説
int h = 175; !int *p; p = &h; *p = 180; !NSLog(@"h: %d", h);
175
h: 0xbfffca44
0xbfffca44
p: 0xbfffca40
![Page 15: ひろ子 in Objective-C](https://reader034.vdocuments.net/reader034/viewer/2022052315/53fdc9608d7f72a81c8b4b16/html5/thumbnails/15.jpg)
解説
int h = 175; !int *p; p = &h; *p = 180; !NSLog(@"h: %d", h);
180
h: 0xbfffca44
0xbfffca44
p: 0xbfffca40
![Page 16: ひろ子 in Objective-C](https://reader034.vdocuments.net/reader034/viewer/2022052315/53fdc9608d7f72a81c8b4b16/html5/thumbnails/16.jpg)
解説
int h = 175; !int *p; p = &h; *p = 180; !NSLog(@"h: %d", h);
2014-05-09 14:09:40.299 Hiroko[23593:60b] h: 180
![Page 17: ひろ子 in Objective-C](https://reader034.vdocuments.net/reader034/viewer/2022052315/53fdc9608d7f72a81c8b4b16/html5/thumbnails/17.jpg)
ひろ子パターン:「どうぞ書き換えて下さい」
![Page 18: ひろ子 in Objective-C](https://reader034.vdocuments.net/reader034/viewer/2022052315/53fdc9608d7f72a81c8b4b16/html5/thumbnails/18.jpg)
ひろ子 in Objective-C?
![Page 19: ひろ子 in Objective-C](https://reader034.vdocuments.net/reader034/viewer/2022052315/53fdc9608d7f72a81c8b4b16/html5/thumbnails/19.jpg)
@interface Hiroko : NSObject !- (void)doHirokoWithHeight:(CGFloat *)height; !@end
…?
![Page 20: ひろ子 in Objective-C](https://reader034.vdocuments.net/reader034/viewer/2022052315/53fdc9608d7f72a81c8b4b16/html5/thumbnails/20.jpg)
Objective-C (Cocoa) では、あまりひろ子パターンは出て来ない。
![Page 21: ひろ子 in Objective-C](https://reader034.vdocuments.net/reader034/viewer/2022052315/53fdc9608d7f72a81c8b4b16/html5/thumbnails/21.jpg)
NSArray *array = @[@"a", @"b", @"c"]; ![array enumerateObjectsUsingBlock: ^(id obj, NSUInteger idx, BOOL *stop) { ! NSLog(@"%@", obj); if([obj isEqual:@"b"]) *stop = YES; }]; !NSLog(@"end");
ひろ子パターン その1: - [NSArray enumerateObjectsUsingBlock:]
![Page 22: ひろ子 in Objective-C](https://reader034.vdocuments.net/reader034/viewer/2022052315/53fdc9608d7f72a81c8b4b16/html5/thumbnails/22.jpg)
NSArray *array = @[@"a", @"b", @"c"]; ![array enumerateObjectsUsingBlock: ^(id obj, NSUInteger idx, BOOL *stop) { ! NSLog(@"%@", obj); if([obj isEqual:@"b"]) *stop = YES; }]; !NSLog(@"end");
ひろ子パターン その1: - [NSArray enumerateObjectsUsingBlock:]
![Page 23: ひろ子 in Objective-C](https://reader034.vdocuments.net/reader034/viewer/2022052315/53fdc9608d7f72a81c8b4b16/html5/thumbnails/23.jpg)
NSArray *array = @[@"a", @"b", @"c"]; ![array enumerateObjectsUsingBlock: ^(id obj, NSUInteger idx, BOOL *stop) { ! NSLog(@"%@", obj); if([obj isEqual:@"b"]) *stop = YES; }]; !NSLog(@"end");
ひろ子パターン その1: - [NSArray enumerateObjectsUsingBlock:]
![Page 24: ひろ子 in Objective-C](https://reader034.vdocuments.net/reader034/viewer/2022052315/53fdc9608d7f72a81c8b4b16/html5/thumbnails/24.jpg)
NSArray *array = @[@"a", @"b", @"c"]; ![array enumerateObjectsUsingBlock: ^(id obj, NSUInteger idx, BOOL *stop) { ! NSLog(@"%@", obj); if([obj isEqual:@"b"]) *stop = YES; }]; !NSLog(@"end");
2014-05-09 14:50:04.508 Hiroko[24612:60b] a 2014-05-09 14:50:04.509 Hiroko[24612:60b] b 2014-05-09 14:50:04.509 Hiroko[24612:60b] end
ひろ子パターン その1: - [NSArray enumerateObjectsUsingBlock:]
![Page 25: ひろ子 in Objective-C](https://reader034.vdocuments.net/reader034/viewer/2022052315/53fdc9608d7f72a81c8b4b16/html5/thumbnails/25.jpg)
NSData *data = ...; !NSError *error = nil; !id json = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error]; if(json && !error) { ... }
ひろ子パターン その2: NSError ** として
![Page 26: ひろ子 in Objective-C](https://reader034.vdocuments.net/reader034/viewer/2022052315/53fdc9608d7f72a81c8b4b16/html5/thumbnails/26.jpg)
NSData *data = ...; !NSError *error = nil; !id json = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error]; if(json && !error) { ... }
ひろ子パターン その2: NSError ** として
nil
NSError *error NSError
![Page 27: ひろ子 in Objective-C](https://reader034.vdocuments.net/reader034/viewer/2022052315/53fdc9608d7f72a81c8b4b16/html5/thumbnails/27.jpg)
NSData *data = ...; !NSError *error = nil; !id json = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error]; if(json && !error) { ... }
ひろ子パターン その2: NSError ** として
nil
NSError *error
0xf8193ab
NSError **errorPtr NSError
引数として渡される
![Page 28: ひろ子 in Objective-C](https://reader034.vdocuments.net/reader034/viewer/2022052315/53fdc9608d7f72a81c8b4b16/html5/thumbnails/28.jpg)
NSData *data = ...; !NSError *error = nil; !id json = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error]; if(json && !error) { ... }
ひろ子パターン その2: NSError ** として
nil
NSError *error
0xf8193ab
NSError **errorPtr
(オブジェクトの実体)
NSError
エラー発生!
![Page 29: ひろ子 in Objective-C](https://reader034.vdocuments.net/reader034/viewer/2022052315/53fdc9608d7f72a81c8b4b16/html5/thumbnails/29.jpg)
NSData *data = ...; !NSError *error = nil; !id json = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error]; if(json && !error) { ... }
ひろ子パターン その2: NSError ** として
0xf19274a
NSError *error
0xf8193ab
NSError **errorPtr
(オブジェクトの実体)
NSError
代入されて処理が戻る
![Page 30: ひろ子 in Objective-C](https://reader034.vdocuments.net/reader034/viewer/2022052315/53fdc9608d7f72a81c8b4b16/html5/thumbnails/30.jpg)
NSData *data = ...; !NSError *error = nil; !id json = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error]; if(json && !error) { ... }
ひろ子パターン その2: NSError ** として
0xf19274a
NSError *error
(オブジェクトの実体)
NSError
↑ nil でなくなっているので通らない
![Page 31: ひろ子 in Objective-C](https://reader034.vdocuments.net/reader034/viewer/2022052315/53fdc9608d7f72a81c8b4b16/html5/thumbnails/31.jpg)
Objective-C でもひろ子はたまに出てくる。
![Page 32: ひろ子 in Objective-C](https://reader034.vdocuments.net/reader034/viewer/2022052315/53fdc9608d7f72a81c8b4b16/html5/thumbnails/32.jpg)
Thanks.