最終更新:2012-06-26 (火) 02:10:49 (1917d)  

NSNumber はてなブックマークを見る
Top / NSNumber

メモ

NSNumber

NSNumber* num;

//真偽値
+numberWithBool:(BOOL)value
-initWithBool:(BOOL)value
-(BOOL)boolValue//取得

//文字
+numberWithChar:(char)value
-initWithChar:(char)value
+numberWithUnisingedChar:(char)value
-initWithUnsignedChar:(char)value

//整数
+numberWithInt:(int)value
-initWithInt:(int)value
-(int)intValue//取得
+numberWithUnisignedInt:(unsigned int)value
-initWithUnisignedInt:(unsigned int)value
-(unsigned int)unsignedIntValue//取得
+numberWithLong:(long)value
-initWithLong:(long)value
-(long)longValue//取得
+numberWithUnisignedLong:(unsigned long)value
-initWithUnisignedLong:(unsigned long)value
-(unsigned long)unsignedLongValue//取得

//小数
+numberWithFloat:(float)value
-initWithFloat:(float)value
-(float)floatValue//取得
+numberWithDouble:value
-initWithDouble:value
-(double)douvleValue//取得

//値の取り出し
-(NSString*)stringValue//どの型で格納した値も文字列として取り出すことができる

NSArrayに追加

NSMutableArray* array = [NSMutableArray array];

int i;
for(i = 0;i<10;i++){
  NSNumber* number = [NSnumber numberWithInt:i];
  //配列に追加
  [array addObject:number];
}