LoginSignup
3
3

More than 5 years have passed since last update.

ブラケット([])によるコレクション要素へのアクセス

Last updated at Posted at 2012-10-25

Xcode4.5からブラケットを使用して要素にアクセスできるようになりました。
以前(Xcode4.4?)から小細工すれば使えていましたが。

配列の場合

NSArray* array = @[@1, @"hoge"];
id tmp = array[0];
NSLog(@"%@", tmp);  //1を出力

辞書の場合

NSDictionary* dict = @{@"key1":@1, @"key2":@"hoge"};
id tmp = dict[@"key2"];
NSLog(@"%@", tmp);  //hogeを出力
3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3