Generic Function

unsafeDowncast(_:to:)

Returns the given instance cast unconditionally to the specified type. 与えられたインスタンスを無条件に特定の型にキャストして返します。

Declaration 宣言

func unsafeDowncast<T>(_ x: AnyObject, to type: T.Type) -> T where T : AnyObject

Parameters パラメータ

x

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

type

The type T to which x is cast. T、それへとxがキャストされます。

Return Value 戻り値

The instance x, cast to type T. インスタンスx、型Tにキャスト済み。

Discussion 解説

The instance passed as x must be an instance of type T. xとして渡されるインスタンスは、型Tのインスタンスでなければなりません。

Use this function instead of unsafeBitcast(_:to:) because this function is more restrictive and still performs a check in debug builds. In -O builds, no test is performed to ensure that x actually has the dynamic type T. この関数をunsafeBitcast(_:to:)の代わりに使ってください、なぜならこの関数はより制限的で依然としてデバッグビルドにおいて検査を実行するからです。-Oビルドにおいて、全くテストは実行されずxが実際に動的型Tを持つことを保証されません。

See Also 参照

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