「Objective-C」プリミティブ型(int型、float型など)をNSNumber型に生成するサンプル

書式
NSNumber *変数名 = [NSNumber numberWithプリミティブ型:値];

使用例
1.int型→NSNumber型
NSNumber *num = [NSNumber numberWithInt:147];

2.long型→NSNumber型
NSNumber *num = [NSNumber numberWithLong:3156897];

3.float型→NSNumber型
NSNumber *num = [NSNumber numberWithFloat:67.243f];

4.double型→NSNumber型
NSNumber *num = [NSNumber numberWithDouble:3.15f];

4. BOOL型→NSNumber型
NSNumber *num = [NSNumber numberWithBool:NO];

5.char型→NSNumber型
NSNumber *num = [NSNumber numberWithChar:d];

Objective-C

Posted by arkgame