An instance of a class. あるクラスのインスタンス。
Initializer
init(_:)
Creates an instance that uniquely identifies the given class instance.
与えられたクラスインスタンスを固有に識別するインスタンスを作成します。
Availability
- iOS 8.0+
- iPadOS 8.0+
- macOS 10.10+
- Mac Catalyst 13.0+
- tvOS 9.0+
- watchOS 2.0+
- Xcode 7.1+
Technology
- Swift Standard Library Swift標準ライブラリ
Declaration 宣言
init(_ x: AnyObject
)
Parameters パラメータ
x
Discussion 解説
The following example creates an example class Integer
and compares instances of the class using their object identifiers and the identical-to operator (===
):
次の例は、ある見本クラスInteger
を作成して、そのクラスのインスタンスをそれらのオブジェクト識別子と同一演算子(===
)を使って比較します:
class IntegerRef {
let value: Int
init(_ value: Int) {
self.value = value
}
}
let x = IntegerRef(10)
let y = x
print(ObjectIdentifier(x) == ObjectIdentifier(y))
// Prints "true"
print(x === y)
// Prints "true"
let z = IntegerRef(10)
print(ObjectIdentifier(x) == ObjectIdentifier(z))
// Prints "false"
print(x === z)
// Prints "false"