More Related Content
More from Taketo Sano (20)
ひろ子 in Objective-C
- 7. int h1 = 195;
hiroko(&h1);
NSLog(@"h1: %d", h1);
- 8. int h1 = 195;
hiroko(&h1);
NSLog(@"h1: %d", h1);
2014-05-09 14:09:40.299 Hiroko[23593:60b] h1: 195
理想通りなのでOK
- 9. 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);
- 10. 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);
ちゃんと超能力が働いてる
- 11. 解説
int h = 175;
!
int *p;
p = &h;
*p = 180;
!
NSLog(@"h: %d", h);
- 12. 解説
int h = 175;
!
int *p;
p = &h;
*p = 180;
!
NSLog(@"h: %d", h);
175
h: 0xbfffca44
- 13. 解説
int h = 175;
!
int *p;
p = &h;
*p = 180;
!
NSLog(@"h: %d", h);
175
h: 0xbfffca44
NULL
p: 0xbfffca40
- 14. 解説
int h = 175;
!
int *p;
p = &h;
*p = 180;
!
NSLog(@"h: %d", h);
175
h: 0xbfffca44
0xbfffca44
p: 0xbfffca40
- 15. 解説
int h = 175;
!
int *p;
p = &h;
*p = 180;
!
NSLog(@"h: %d", h);
180
h: 0xbfffca44
0xbfffca44
p: 0xbfffca40
- 16. 解説
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
- 21. 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:]
- 22. 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:]
- 23. 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:]
- 24. 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:]
- 25. NSData *data = ...;
!
NSError *error = nil;
!
id json = [NSJSONSerialization
JSONObjectWithData:data
options:0
error:&error];
if(json && !error) {
...
}
ひろ子パターン その2:
NSError ** として
- 26. NSData *data = ...;
!
NSError *error = nil;
!
id json = [NSJSONSerialization
JSONObjectWithData:data
options:0
error:&error];
if(json && !error) {
...
}
ひろ子パターン その2:
NSError ** として
nil
NSError *error NSError
- 27. 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
引数として渡される
- 28. 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
エラー発生!
- 29. 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
代入されて処理が戻る
- 30. NSData *data = ...;
!
NSError *error = nil;
!
id json = [NSJSONSerialization
JSONObjectWithData:data
options:0
error:&error];
if(json && !error) {
...
}
ひろ子パターン その2:
NSError ** として
0xf19274a
NSError *error
(オブジェクトの実体)
NSError
↑ nil でなくなっているので通らない