2012年3月17日土曜日

文字列⇔数値変換


Cocoaでの数値、文字列相互変換に使うメソッドです。

NSStringのメソッドで文字列を数値に変換する。
– doubleValue
– floatValue
– intValue
– integerValue
– longLongValue
– boolValue

NSNumberのメソッドで数値を文字列に変換する。
数値からNSNumberオブジェクトを作るファクトリメソッド
+ numberWithBool:
+ numberWithChar:
+ numberWithDouble:
+ numberWithFloat:
+ numberWithInt:
+ numberWithInteger:
+ numberWithLong:
+ numberWithLongLong:
+ numberWithShort:
+ numberWithUnsignedChar:
+ numberWithUnsignedInt:
+ numberWithUnsignedInteger:
+ numberWithUnsignedLong:
+ numberWithUnsignedLongLong:
+ numberWithUnsignedShort:

文字列へ変換
– stringValue
– descriptionWithLocale:

数値の型変換
– boolValue
– charValue
– decimalValue
– doubleValue
– floatValue
– intValue
– integerValue
– longLongValue
– longValue
– shortValue
– unsignedCharValue
– unsignedIntegerValue
– unsignedIntValue
– unsignedLongLongValue
– unsignedLongValue
– unsignedShortValue

元データの型
- objCType
(ただしオブジェクトを生成するときに使用したメソッドと一致しない場合がある、となってます。どのような場合に一致しないかはわかりません。)

0 件のコメント: