&tag(Objective-C/規約);
*目次 [#x6751f4c]
#contents
*参考情報 [#z3389213]
-[[Objective-C]]

*命名規約 [#he17573e]
-[[iphone - Objective C method naming convention - Stack Overflow:http://stackoverflow.com/questions/8410602/objective-c-method-naming-convention]]
*インスタンス変数とプロパティ [#x76db8f1]
-[[プロパティに対応するインスタンス変数の命名規則について - Awaresoft:http://www.awaresoft.jp/ios-dev/item/115-ivar-naming-convention.html]]
-[[objective c - Should I use properties or direct reference when accessing instance variables internally? - Stack Overflow:http://stackoverflow.com/questions/3753130/should-i-use-properties-or-direct-reference-when-accessing-instance-variables-in]]
-[[objective c - IBOutlets, instance variables and properties: Best Practices - Stack Overflow:http://stackoverflow.com/questions/6113755/iboutlets-instance-variables-and-properties-best-practices]]
-クラス内部からインスタンス変数にアクセスするかどうかは議論がわかれるところらしい。Appleのコーディング規約では「 you should not access instance variables directly, instead you should use accessor methods (you do access instance variables directly in init and dealloc methods)」とありinitまたはdealloc以外はプロパティ経由でアクセスせよとある。
-ということを考えると、「[[[iPhone] メモリ管理 - かみやんの技術者日記:http://d.hatena.ne.jp/kamiyan2/20110220]]」にあるように、内部からもプロパティ経由で完全にアクセスするほうがいいのかな。メモリ管理も簡単になるし。UICatalogなどはそうなっていた。

**現段階(2013/02/19(火))よさげな方法 [#w0975757]
-プロパティは*.hファイルに宣言するだけでいける。synthesizeも不要。フィールドは_textViewでさわれるけど。
 @property(nonatomic, retain) UITextView *textView;
-初期化。initと同時にautoreleaseしておく
#pre{{
-(void)viewDidLoad {
    self.textView = [[UITextView alloc] initWithFrame:[self.view bounds]];
}
}}
-使用。常にself.textViewで使う。
-解放。dealloで解放
#pre{{
-(void)dealloc {
  self.textView = nil;
}
}}
-privateなプロパティも使う。
#pre{{
@interface Person () 
@property (nonatomic, retain) NSString* name;
@end
}}



トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS