25
23

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

NSArray、NSDictionary、NSNumberの省略形

Last updated at Posted at 2013-04-08

Xcode4.3から
NSArray、NSDictionary、NSNumberを省略して書けるようになってた・・・
知らなかったので忘れないよう、備忘録に

NSNumber

整数(longまで):@10
小数(double) :@0.1
小数(float) :@0.1f
文字列 :@'a'
16進数 :@0xff
BOOL値 :@(TRUE)、@TRUE@YES@true

NSArray

@[@"val1", @"val2", @"val3"]
@[@10, @0.1f, @(TRUE)]

NSDictionary

@{@"key1":@(TRUE), @"key2":@100, @"key3":@"value3"}

  
  

(@が大活躍だ~
(BOOL値は、YES・NOをAPPLEは推奨してるらしいんですが、C,C++も書くことがあるので、TRUEに統一しちゃってます^^;

参考:
http://www.tokoro.me/2012/08/12/objc-new-statements/

(追記修正
NSNumberに代入できる文字は、charの1文字だけっぽいので修正
Ushio@githubさんのご指摘で気付きました、感謝っす

(追記修正、その2
BOOL値は、@TRUE@YES@trueのように記載も可能でした
psihyさん、コメント感謝です~
(コード補間はしてくれないのか~

25
23
6

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
25
23

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?