引っ越し後の日記はコチラです
tokoromのその他の日記
- vim関連: vimまっしぐら★
- それ以外: 寄り道ばかりの お勉強日記★
2010-07-11
いつのまにかインスタンス変数の記述が省略できるようになってた
iPhone | |
これってはじめからでしたっけ?
プロパティを使う場合、もともと
// 定義 @interface UIViewBoundsSample : UIViewController { @private UILabel* label0; } @property (nonatomic, retain) UILabel* label0; @end // 実装 @implementation UIViewBoundsSample @synthesize label0; - (void)dealloc { self.label0 = nil; [super dealloc]; } @end
のように、
- インスタンス変数の定義
- @property
- @synthesize
の3つ全てを記述しないといけなかったと思うのですが、少なくとも今つかっているXCode3.2.3だと「インスタンス変数の定義」を省略してもきちんと動いています。
いつからだろう?
なにはともあれ、コード量が減るのは嬉しいことです。
// 定義 @interface UIViewBoundsSample : UIViewController @property (nonatomic, retain) UILabel* label0; @end // 実装 @implementation UIViewBoundsSample @synthesize label0; - (void)dealloc { self.label0 = nil; [super dealloc]; } @end
トラックバック - http://iphone-dev.g.hatena.ne.jp/tokorom/20100711
リンク元
- 328 http://token.sakura.ne.jp/wp/?p=568
- 284 http://iphone-dev.g.hatena.ne.jp/
- 258 http://pipes.yahoo.com/pipes/pipe.info?_id=yvr0QEHa3RGA4YVKbbsjiw
- 246 http://www.google.co.jp/search?q=NSUserDefaults&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:ja-JP-mac:official&hl=ja&client=firefox-a
- 141 http://twitter.com/tokorom
- 77 http://www.google.co.jp/search?q=uiimage+nsdata&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:ja-JP-mac:official&hl=ja&client=firefox-a
- 69 http://www.cocoalife.net/2010/04/post_543.html
- 60 http://d.hatena.ne.jp/glass-_-onion/20100605/1275684478
- 59 http://d.hatena.ne.jp/m765/20100212/1265919176
- 53 http://www.google.co.jp/search?q=NSUserDefaults&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:ja:official&hl=ja&client=firefox-a
"modern"なランタイム(iPhoneと64bit Mac)であればこの記述方法が可能なようです。SDK4.0でシミュレータのランタイムが変更になったので、SDK4.0からは、実機/シミュレータともに使えるようになったのだと思います。逆に、SDK3.2(もしくはそれ以前)を使うと、実機ビルドではOK、シミュレータビルドではNGになるのではないかと思います。
何はともあれ、シミュレータと実機で環境が統一されつつあるのは嬉しいことですね。
この"modern"なランタイムには、ほかにもいろいろとメリットがありそうです。私ももう少し調べてみようと思います。
ひとまずここが詳しそうです:
http://cocoawithlove.com/2010/03/dynamic-ivars-solving-fragile-base.html
"modern"なランタイムに他にも有用な更新があるかもしれないと思うと楽しみです!
ぼくも調べてみます!