Generic Function

unsafeBitCast(_:to:)

Returns the bits of the given instance, interpreted as having the specified type. 与えられたインスタンスのビットを返します、指定された型を持つと解釈されます。

Declaration 宣言

func unsafeBitCast<T, U>(_ x: T, to type: U.Type) -> U

Parameters パラメータ

x

The instance to cast to type. typeにキャストすることになるインスタンス。

type

The type to cast x to. type and the type of x must have the same size of memory representation and compatible memory layout. xをこれにキャストすることになる型。typexの型は、同じ大きさのメモリ表現を持ち、互換メモリレイアウトを持たなければなりません。

Return Value 戻り値

A new instance of type U, cast from x. Uの新しいインスタンス、xからキャストされます。

Discussion 解説

Use this function only to convert the instance passed as x to a layout-compatible type when conversion through other means is not possible. Common conversions supported by the Swift standard library include the following: この関数をxとして渡されるインスタンスをレイアウト互換の型へと、その変換が他の手段では可能でない場合に、変換するのにだけ使ってください。Swift標準ライブラリによってサポートされる一般的な変換は、以下を含みます:

  • Value conversion from one integer type to another. Use the destination type’s initializer or the numericCast(_:) function. ある整数型から別のものへの値変換。行き先の型のもつイニシャライザまたはnumericCast(_:)関数を使ってください。

  • Bitwise conversion from one integer type to another. Use the destination type’s init(truncatingIfNeeded:) or init(bitPattern:) initializer. ある整数型から別のものへのビット単位変換。行き先の型のもつinit(truncatingIfNeeded:)またはinit(bitPattern:)イニシャライザを使ってください。

  • Conversion from a pointer to an integer value with the bit pattern of the pointer’s address in memory, or vice versa. Use the init(bitPattern:) initializer for the destination type. あるポインタからそのポインタのもつメモリでのアドレスのビットパターンをもつ整数値への変換、またはその逆。行き先の型のためのinit(bitPattern:)イニシャライザを使ってください。

  • Casting an instance of a reference type. Use the casting operators (as, as!, or as?) or the unsafeDowncast(_:to:) function. Do not use unsafeBitCast(_:to:) with class or pointer types; doing so may introduce undefined behavior. 参照型のインスタンスのキャスト。キャスト演算子(asas!、またはas?)またはunsafeDowncast(_:to:)関数を使ってください。unsafeBitCast(_:to:)をクラスまたはポインタ型で使わないでください;そうすることは未定義挙動を導きます。

See Also 参照

Instance Casting インスタンスのキャスト