簡潔だが俯瞰として参考になる。
まとめの表

Nil ってあまり見覚えが無い。
Published on 2013年1月8日火曜日 Leave your thoughts »
|
|
Tweet |
Published on 2012年12月20日木曜日 Leave your thoughts »
|
|
Tweet |
instancetype なんてキーワードが使えるらしい。
@implementation TextViewController
- (instancetype)init
{
self = [super initWithNibName:@"TextViewController" bundle:nil];
if (self) {
//...
}
return self;
}と書いてあり、@interface の中で使うと、指定の型チェックを行うことが出来る機能のようです。つまり、サブクラスの中で戻り値の型を適当に定義したときにエラーが表示されるようになるようです。idの場合は、基本的にどんな型を返してもエラーになりませんが、instancetypeを使うことによって、型チェックの機能をコンパイラで使用することが出来ます。
この instancetype は、Clang 3.0, xcode 4.3 から使用できる機能のようです。ただ、条件として、メソッドの戻り値にしか使用できないという条件があるようで、だそうです。
This post is archived under Clang, Objective-C
Published on 2012年4月6日金曜日 Leave your thoughts »
|
|
Tweet |
Published on 2012年3月19日月曜日 Leave your thoughts »
|
|
Tweet |
いい記事。
1.プロパティに対応するインスタンス変数はヘッダファイルで宣言する必要はまずない。(iOSのバージョンに関係なく)
2.プロパティに対応するインスタンス変数はsynthesizeで常に別名をつけるべき。
3.インスタンス変数名はプロパティ名の前に_をつけたものにする。
4.インスタンス変数にアクセスするときは、クラス内からでも常にアクセッサメソッドを通して行うようにする。(setter/getter内やinit, dealloc以外)
This post is archived under Objective-C
Published on 2012年3月16日金曜日 Leave your thoughts »
|
|
Tweet |
Objective-Cのリテラル強化きた。
NSArray *array =int値、float値や BOOL値 に @ を付けると NSNumberに変更される。
[NSArray arrayWithObjects: @0, @23, @3.1415, @YES, nil];
NSArray *gronk = @[ @"hi", @"bork", @23, @YES ];
NSArray *gronk = @[ @"hi", @"bork", @23, @YES ];
NSLog (@"gronk 0: %@", gronk[0]);
NSLog (@"gronk 2: %@", gronk[2]);
NSArray *nesting = @[ @"hi", @[ @"ohai" ] ];
NSLog (@"nesting: %@", nesting[1][0]);
-> nesting: ohai
mutt[0] = @"aaa";さらにインデックスが範囲外の場合、自動的にインサート(insertObject:index:)される。
mutt[3] = @"d";
mutt[4] = @"e";
NSDictionary *splunge = @{ @"hi" : @"bork", @"greeble" : @"bork" };
NSLog (@"splunge %@", splunge);
->splunge {
greeble = bork;
hi = bork;
}
NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:
[NSFont userFontOfSize: 150.0], NSFontAttributeName,
[NSNumber numberWithFloat: 3.0], NSStrokeWidthAttributeName,
[NSColor blueColor], NSStrokeColorAttributeName,
[NSNumber numberWithInt: 10], NSKernAttributeName,
[NSNumber numberWithFloat: 0.5], NSObliquenessAttributeName,
nil];こうなるNSDictionary *attributes = @{
NSFontAttributeName : [NSFont userFontOfSize: 150.0],
NSStrokeWidthAttributeName : @3.0,
NSStrokeColorAttributeName : [NSColor blueColor],
NSKernAttributeName : @10,
NSObliquenessAttributeName : @0.5
};すっきりしてわかりやすい。NSDictionary *splunge = @{ @"hi" : @"bork", @"greeble" : @"bork" };
NSLog (@"%@", splunge[@"greeble"]);
NSLog (@"%@", splunge[@"ACK"]);
NSDictionary *nest = @{ @"hi" : @"ohai",
@"ichc" : @{ @"oop" : @"ack"} };
NSLog (@"nest: %@", nest);
NSLog (@"noost: %@", nest[@"ichc"][@"oop"]);
NSLog (@"nist: %@", nest[@"ichc.oop"]); // try a key path
#import
NSString *thing = @"thing 1";
NSArray *array = @[ @"thing 2" ];
@implementation BNRGroovyObject
...
This post is archived under Clang, Objective-C
Published on 2011年12月19日月曜日 Leave your thoughts »
|
|
Tweet |