SwiftのNSNumberでの符号なし整数の扱い

(追記 2015/10/22)
Xcode7.1出ました。修正されました。
リリースノートには

The NSNumberunsignedIntegerValue property now has the type UInt instead of Int, as do other methods and properties that use the NSUInteger type in Objective-C and whose names contain "unsigned..".
Most other uses of NSUInteger in system frameworks are imported as Int as they were in Xcode 7. (19134055)


と書かれています。
NSNumberは無事
public init(unsignedInteger value: UInt)
public var unsignedIntegerValue: UInt { get }
に変更されました。

(追記 2015/9/25)
Xcode7.1より修正されるようです。



【Xcode 6.1】
SwiftのNSNumberではUIntとなりそうなところでなぜかIntが定義されています。
具体的には初期化メソッドの
init(unsignedInteger value: Int)
と値取り出しの
var unsignedIntegerValue: Int { get }
です。
間違いかと思ったのですが、両方で同じように変わっているのでわざとかなという気もします。

参考までにNSNumberで扱われているその他の型がObjective-CとSwiftでどう対応しているかは

BOOL(Objective-C)
Bool(Swift)

char(Objective-C)
Int8(Swift)

double(Objective-C)
Double(Swift)

float(Objective-C)
Float(Swift)

int(Objective-C)
Int32(Swift)
どちらも32

NSInteger(Objective-C)
Int(Swift)
どちらも32環境で32、64環境で64

long long(Objective-C)
Int64(Swift)
どちらも64

long(Objective-C)
Int(Swift)
どちらも32環境で32、64環境で64

short(Objective-C)
Int16(Swift)

unsigned char(Objective-C)
UInt8(Swift)

NSUInteger(Objective-C)
Int(Swift)

unsigned int(Objective-C)
UInt32(Swift)

unsigned long long(Objective-C)
UInt64(Swift)

unsigned long(Objective-C)
UInt(Swift)

unsigned short(Objective-C)
UInt16(Swift)


まだ仕様を全部読んでいないのでどこかに理由が書いてあるのかもしれません。

コメント

このブログの人気の投稿

Swiftのコンパイルエラー寄せ集め

コンパイルエラー覚え書き(Objective-C)

AVAudioSession細かいことまとめ(late 2014)