SlideShare a Scribd company logo
1 of 32
Download to read offline
who is ひろ子  ?
void hiroko(int height)
{
if(height < 180)
height = 180;
}
正しくない hiroko の実装
void hiroko(int *height)
{
if(*height < 180)
*height = 180;
}
正しい hiroko の実装(多分
int h1 = 195;
hiroko(&h1);
NSLog(@"h1: %d", h1);
int h1 = 195;
hiroko(&h1);
NSLog(@"h1: %d", h1);
2014-05-09 14:09:40.299 Hiroko[23593:60b] h1: 195
理想通りなのでOK
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);
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);
ちゃんと超能力が働いてる
解説
int h = 175;
!
int *p;
p = &h;
*p = 180;
!
NSLog(@"h: %d", h);
解説
int h = 175;
!
int *p;
p = &h;
*p = 180;
!
NSLog(@"h: %d", h);
175
h: 0xbfffca44
解説
int h = 175;
!
int *p;
p = &h;
*p = 180;
!
NSLog(@"h: %d", h);
175
h: 0xbfffca44
NULL
p: 0xbfffca40
解説
int h = 175;
!
int *p;
p = &h;
*p = 180;
!
NSLog(@"h: %d", h);
175
h: 0xbfffca44
0xbfffca44
p: 0xbfffca40
解説
int h = 175;
!
int *p;
p = &h;
*p = 180;
!
NSLog(@"h: %d", h);
180
h: 0xbfffca44
0xbfffca44
p: 0xbfffca40
解説
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
ひろ子パターン:


「どうぞ書き換えて下さい」
ひろ子 in Objective-C?
@interface Hiroko : NSObject
!
- (void)doHirokoWithHeight:(CGFloat *)height;
!
@end
…?
Objective-C (Cocoa) では、


あまりひろ子パターンは出て来ない。
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:]
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:]
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:]
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:]
NSData *data = ...;
!
NSError *error = nil;
!
id json = [NSJSONSerialization
JSONObjectWithData:data
options:0
error:&error];
if(json && !error) {
...
}
ひろ子パターン その2:
NSError ** として
NSData *data = ...;
!
NSError *error = nil;
!
id json = [NSJSONSerialization
JSONObjectWithData:data
options:0
error:&error];
if(json && !error) {
...
}
ひろ子パターン その2:
NSError ** として
nil
NSError *error NSError
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
引数として渡される
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
エラー発生!
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
代入されて処理が戻る
NSData *data = ...;
!
NSError *error = nil;
!
id json = [NSJSONSerialization
JSONObjectWithData:data
options:0
error:&error];
if(json && !error) {
...
}
ひろ子パターン その2:
NSError ** として
0xf19274a
NSError *error
(オブジェクトの実体)
NSError
↑ nil でなくなっているので通らない
Objective-C でも


ひろ子はたまに出てくる。
Thanks.

More Related Content

Viewers also liked

2.5 Trillion Oil Scam
2.5 Trillion Oil Scam2.5 Trillion Oil Scam
2.5 Trillion Oil Scamtheoilman
 
07 09 04 Ctqi Standard
07 09 04 Ctqi Standard07 09 04 Ctqi Standard
07 09 04 Ctqi StandardKieran F Ring
 
Isotopes And Radioactivity 09
Isotopes And Radioactivity 09Isotopes And Radioactivity 09
Isotopes And Radioactivity 09Paula Mills
 
The Art Of Writing A Business Plan (Zafar)
The Art Of Writing A Business Plan (Zafar)The Art Of Writing A Business Plan (Zafar)
The Art Of Writing A Business Plan (Zafar)Naeem Zafar
 
Cmc chapter 09
Cmc chapter 09Cmc chapter 09
Cmc chapter 09Jane Hamze
 
Python and R for quantitative finance
Python and R for quantitative financePython and R for quantitative finance
Python and R for quantitative financeLuca Sbardella
 
09. Development Plan For Pcmc
09. Development Plan For Pcmc09. Development Plan For Pcmc
09. Development Plan For PcmcRanjit Gadgil
 
Abc analysis1234
Abc analysis1234Abc analysis1234
Abc analysis1234Ashok Reddy
 
Seductive Interactions (Idea 09 Version)
Seductive Interactions (Idea 09 Version)Seductive Interactions (Idea 09 Version)
Seductive Interactions (Idea 09 Version)Stephen Anderson
 
Infographics Jayan Narayanan
Infographics   Jayan NarayananInfographics   Jayan Narayanan
Infographics Jayan NarayananJayan Narayanan
 
JavaScript for PHP developers
JavaScript for PHP developersJavaScript for PHP developers
JavaScript for PHP developersStoyan Stefanov
 
Unbezahlte arbeitszeit in_Österreich
Unbezahlte arbeitszeit in_ÖsterreichUnbezahlte arbeitszeit in_Österreich
Unbezahlte arbeitszeit in_ÖsterreichFESD GKr
 
mediscript Kalendar 2013 "Lernen heisst Entdecken"
mediscript Kalendar 2013 "Lernen heisst Entdecken"mediscript Kalendar 2013 "Lernen heisst Entdecken"
mediscript Kalendar 2013 "Lernen heisst Entdecken"mediscript Team
 
E Co C Bratislava 09 Persoenlichkeit
E Co C Bratislava 09 PersoenlichkeitE Co C Bratislava 09 Persoenlichkeit
E Co C Bratislava 09 Persoenlichkeitthomasabauer
 
Lernen Mit Web 2.0 (IHK Stuttgart Juli 2009)
Lernen Mit Web 2.0 (IHK Stuttgart Juli 2009)Lernen Mit Web 2.0 (IHK Stuttgart Juli 2009)
Lernen Mit Web 2.0 (IHK Stuttgart Juli 2009)Martina Goehring
 
Kelantan
KelantanKelantan
Kelantanwmzuri
 
Financial Institutions Must Support Their Clients on Twitter
Financial Institutions Must Support Their Clients on TwitterFinancial Institutions Must Support Their Clients on Twitter
Financial Institutions Must Support Their Clients on TwitterChristophe Langlois
 
EdChang - Parallel Algorithms For Mining Large Scale Data
EdChang - Parallel Algorithms For Mining Large Scale DataEdChang - Parallel Algorithms For Mining Large Scale Data
EdChang - Parallel Algorithms For Mining Large Scale Datagu wendong
 

Viewers also liked (20)

Tagging - web 2 expo 2008
Tagging - web 2 expo 2008Tagging - web 2 expo 2008
Tagging - web 2 expo 2008
 
2.5 Trillion Oil Scam
2.5 Trillion Oil Scam2.5 Trillion Oil Scam
2.5 Trillion Oil Scam
 
07 09 04 Ctqi Standard
07 09 04 Ctqi Standard07 09 04 Ctqi Standard
07 09 04 Ctqi Standard
 
Isotopes And Radioactivity 09
Isotopes And Radioactivity 09Isotopes And Radioactivity 09
Isotopes And Radioactivity 09
 
The Art Of Writing A Business Plan (Zafar)
The Art Of Writing A Business Plan (Zafar)The Art Of Writing A Business Plan (Zafar)
The Art Of Writing A Business Plan (Zafar)
 
Cmc chapter 09
Cmc chapter 09Cmc chapter 09
Cmc chapter 09
 
Python and R for quantitative finance
Python and R for quantitative financePython and R for quantitative finance
Python and R for quantitative finance
 
09. Development Plan For Pcmc
09. Development Plan For Pcmc09. Development Plan For Pcmc
09. Development Plan For Pcmc
 
Abc analysis1234
Abc analysis1234Abc analysis1234
Abc analysis1234
 
Seductive Interactions (Idea 09 Version)
Seductive Interactions (Idea 09 Version)Seductive Interactions (Idea 09 Version)
Seductive Interactions (Idea 09 Version)
 
PMP Preparation - 09 Human Resource Management
PMP Preparation - 09 Human Resource ManagementPMP Preparation - 09 Human Resource Management
PMP Preparation - 09 Human Resource Management
 
Infographics Jayan Narayanan
Infographics   Jayan NarayananInfographics   Jayan Narayanan
Infographics Jayan Narayanan
 
JavaScript for PHP developers
JavaScript for PHP developersJavaScript for PHP developers
JavaScript for PHP developers
 
Unbezahlte arbeitszeit in_Österreich
Unbezahlte arbeitszeit in_ÖsterreichUnbezahlte arbeitszeit in_Österreich
Unbezahlte arbeitszeit in_Österreich
 
mediscript Kalendar 2013 "Lernen heisst Entdecken"
mediscript Kalendar 2013 "Lernen heisst Entdecken"mediscript Kalendar 2013 "Lernen heisst Entdecken"
mediscript Kalendar 2013 "Lernen heisst Entdecken"
 
E Co C Bratislava 09 Persoenlichkeit
E Co C Bratislava 09 PersoenlichkeitE Co C Bratislava 09 Persoenlichkeit
E Co C Bratislava 09 Persoenlichkeit
 
Lernen Mit Web 2.0 (IHK Stuttgart Juli 2009)
Lernen Mit Web 2.0 (IHK Stuttgart Juli 2009)Lernen Mit Web 2.0 (IHK Stuttgart Juli 2009)
Lernen Mit Web 2.0 (IHK Stuttgart Juli 2009)
 
Kelantan
KelantanKelantan
Kelantan
 
Financial Institutions Must Support Their Clients on Twitter
Financial Institutions Must Support Their Clients on TwitterFinancial Institutions Must Support Their Clients on Twitter
Financial Institutions Must Support Their Clients on Twitter
 
EdChang - Parallel Algorithms For Mining Large Scale Data
EdChang - Parallel Algorithms For Mining Large Scale DataEdChang - Parallel Algorithms For Mining Large Scale Data
EdChang - Parallel Algorithms For Mining Large Scale Data
 

More from Taketo Sano

Divisibility of Lee’s class and its relation with Rasmussen’s invariant / 201...
Divisibility of Lee’s class and its relation with Rasmussen’s invariant / 201...Divisibility of Lee’s class and its relation with Rasmussen’s invariant / 201...
Divisibility of Lee’s class and its relation with Rasmussen’s invariant / 201...Taketo Sano
 
トポロジーと圏論の夜明け
トポロジーと圏論の夜明けトポロジーと圏論の夜明け
トポロジーと圏論の夜明けTaketo Sano
 
Swift で数学研究のススメ
Swift で数学研究のススメSwift で数学研究のススメ
Swift で数学研究のススメTaketo Sano
 
(意欲的な中高生のための)トポロジー・圏論・コンピュータ
(意欲的な中高生のための)トポロジー・圏論・コンピュータ(意欲的な中高生のための)トポロジー・圏論・コンピュータ
(意欲的な中高生のための)トポロジー・圏論・コンピュータTaketo Sano
 
特性類の気持ち
特性類の気持ち特性類の気持ち
特性類の気持ちTaketo Sano
 
Swift で数学のススメ 〜 プログラミングと数学は同時に学べ
Swift で数学のススメ 〜 プログラミングと数学は同時に学べSwift で数学のススメ 〜 プログラミングと数学は同時に学べ
Swift で数学のススメ 〜 プログラミングと数学は同時に学べTaketo Sano
 
山手線は丸いのか?プログラマのためのトポロジー入門
山手線は丸いのか?プログラマのためのトポロジー入門山手線は丸いのか?プログラマのためのトポロジー入門
山手線は丸いのか?プログラマのためのトポロジー入門Taketo Sano
 
何もないところから数を作る
何もないところから数を作る何もないところから数を作る
何もないところから数を作るTaketo Sano
 
「数える」とは何か? 〜 「とは何か?」を問う、AI時代の数学
「数える」とは何か? 〜 「とは何か?」を問う、AI時代の数学「数える」とは何か? 〜 「とは何か?」を問う、AI時代の数学
「数える」とは何か? 〜 「とは何か?」を問う、AI時代の数学Taketo Sano
 
情報幾何学 #2.4
情報幾何学 #2.4情報幾何学 #2.4
情報幾何学 #2.4Taketo Sano
 
情報幾何学 #2 #infogeo16
情報幾何学 #2 #infogeo16情報幾何学 #2 #infogeo16
情報幾何学 #2 #infogeo16Taketo Sano
 
objc2swift 〜 Objective-C から Swift への「コード&パラダイム」シフト
objc2swift 〜 Objective-C から Swift への「コード&パラダイム」シフトobjc2swift 〜 Objective-C から Swift への「コード&パラダイム」シフト
objc2swift 〜 Objective-C から Swift への「コード&パラダイム」シフトTaketo Sano
 
何もないところから数を作る
何もないところから数を作る何もないところから数を作る
何もないところから数を作るTaketo Sano
 
objc2swift (続・自動変換の野望)
objc2swift (続・自動変換の野望) objc2swift (続・自動変換の野望)
objc2swift (続・自動変換の野望) Taketo Sano
 
さらに上を目指すための iOS アプリ設計
さらに上を目指すための iOS アプリ設計さらに上を目指すための iOS アプリ設計
さらに上を目指すための iOS アプリ設計Taketo Sano
 
基底変換、固有値・固有ベクトル、そしてその先
基底変換、固有値・固有ベクトル、そしてその先基底変換、固有値・固有ベクトル、そしてその先
基底変換、固有値・固有ベクトル、そしてその先Taketo Sano
 
objc2swift (自動変換の野望)
objc2swift (自動変換の野望)objc2swift (自動変換の野望)
objc2swift (自動変換の野望)Taketo Sano
 
プログラマのための線形代数再入門2 〜 要件定義から学ぶ行列式と逆行列
プログラマのための線形代数再入門2 〜 要件定義から学ぶ行列式と逆行列プログラマのための線形代数再入門2 〜 要件定義から学ぶ行列式と逆行列
プログラマのための線形代数再入門2 〜 要件定義から学ぶ行列式と逆行列Taketo Sano
 
2015 02-18 xxx-literalconvertible
2015 02-18 xxx-literalconvertible2015 02-18 xxx-literalconvertible
2015 02-18 xxx-literalconvertibleTaketo Sano
 
let UIWebView as WKWebView
let UIWebView as WKWebViewlet UIWebView as WKWebView
let UIWebView as WKWebViewTaketo Sano
 

More from Taketo Sano (20)

Divisibility of Lee’s class and its relation with Rasmussen’s invariant / 201...
Divisibility of Lee’s class and its relation with Rasmussen’s invariant / 201...Divisibility of Lee’s class and its relation with Rasmussen’s invariant / 201...
Divisibility of Lee’s class and its relation with Rasmussen’s invariant / 201...
 
トポロジーと圏論の夜明け
トポロジーと圏論の夜明けトポロジーと圏論の夜明け
トポロジーと圏論の夜明け
 
Swift で数学研究のススメ
Swift で数学研究のススメSwift で数学研究のススメ
Swift で数学研究のススメ
 
(意欲的な中高生のための)トポロジー・圏論・コンピュータ
(意欲的な中高生のための)トポロジー・圏論・コンピュータ(意欲的な中高生のための)トポロジー・圏論・コンピュータ
(意欲的な中高生のための)トポロジー・圏論・コンピュータ
 
特性類の気持ち
特性類の気持ち特性類の気持ち
特性類の気持ち
 
Swift で数学のススメ 〜 プログラミングと数学は同時に学べ
Swift で数学のススメ 〜 プログラミングと数学は同時に学べSwift で数学のススメ 〜 プログラミングと数学は同時に学べ
Swift で数学のススメ 〜 プログラミングと数学は同時に学べ
 
山手線は丸いのか?プログラマのためのトポロジー入門
山手線は丸いのか?プログラマのためのトポロジー入門山手線は丸いのか?プログラマのためのトポロジー入門
山手線は丸いのか?プログラマのためのトポロジー入門
 
何もないところから数を作る
何もないところから数を作る何もないところから数を作る
何もないところから数を作る
 
「数える」とは何か? 〜 「とは何か?」を問う、AI時代の数学
「数える」とは何か? 〜 「とは何か?」を問う、AI時代の数学「数える」とは何か? 〜 「とは何か?」を問う、AI時代の数学
「数える」とは何か? 〜 「とは何か?」を問う、AI時代の数学
 
情報幾何学 #2.4
情報幾何学 #2.4情報幾何学 #2.4
情報幾何学 #2.4
 
情報幾何学 #2 #infogeo16
情報幾何学 #2 #infogeo16情報幾何学 #2 #infogeo16
情報幾何学 #2 #infogeo16
 
objc2swift 〜 Objective-C から Swift への「コード&パラダイム」シフト
objc2swift 〜 Objective-C から Swift への「コード&パラダイム」シフトobjc2swift 〜 Objective-C から Swift への「コード&パラダイム」シフト
objc2swift 〜 Objective-C から Swift への「コード&パラダイム」シフト
 
何もないところから数を作る
何もないところから数を作る何もないところから数を作る
何もないところから数を作る
 
objc2swift (続・自動変換の野望)
objc2swift (続・自動変換の野望) objc2swift (続・自動変換の野望)
objc2swift (続・自動変換の野望)
 
さらに上を目指すための iOS アプリ設計
さらに上を目指すための iOS アプリ設計さらに上を目指すための iOS アプリ設計
さらに上を目指すための iOS アプリ設計
 
基底変換、固有値・固有ベクトル、そしてその先
基底変換、固有値・固有ベクトル、そしてその先基底変換、固有値・固有ベクトル、そしてその先
基底変換、固有値・固有ベクトル、そしてその先
 
objc2swift (自動変換の野望)
objc2swift (自動変換の野望)objc2swift (自動変換の野望)
objc2swift (自動変換の野望)
 
プログラマのための線形代数再入門2 〜 要件定義から学ぶ行列式と逆行列
プログラマのための線形代数再入門2 〜 要件定義から学ぶ行列式と逆行列プログラマのための線形代数再入門2 〜 要件定義から学ぶ行列式と逆行列
プログラマのための線形代数再入門2 〜 要件定義から学ぶ行列式と逆行列
 
2015 02-18 xxx-literalconvertible
2015 02-18 xxx-literalconvertible2015 02-18 xxx-literalconvertible
2015 02-18 xxx-literalconvertible
 
let UIWebView as WKWebView
let UIWebView as WKWebViewlet UIWebView as WKWebView
let UIWebView as WKWebView
 

ひろ子 in Objective-C

  • 1.
  • 3.
  • 4.
  • 5. void hiroko(int height) { if(height < 180) height = 180; } 正しくない hiroko の実装
  • 6. void hiroko(int *height) { if(*height < 180) *height = 180; } 正しい hiroko の実装(多分
  • 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
  • 19. @interface Hiroko : NSObject ! - (void)doHirokoWithHeight:(CGFloat *)height; ! @end …?
  • 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 でなくなっているので通らない