Instance Method インスタンスメソッド

isEqual(_:)

Returns a Boolean value that indicates whether the receiver and a given object are equal. レシーバと与えられたオブジェクトが等しいかどうかを指し示すブール値を返します。

Declaration 宣言

func isEqual(_ object: Any?) -> Bool

Parameters パラメータ

anObject

The object to be compared to the receiver. May be nil, in which case this method returns false.

Return Value 戻り値

true if the receiver and anObject are equal, otherwise false.

Discussion 解説

This method defines what it means for instances to be equal. For example, a container object might define two containers as equal if their corresponding objects all respond true to an isEqual(_:) request. See the NSData, NSDictionary, NSArray, and NSString class specifications for examples of the use of this method.

If two objects are equal, they must have the same hash value. This last point is particularly important if you define isEqual(_:) in a subclass and intend to put instances of that subclass into a collection. Make sure you also define hash in your subclass.

See Also 参照

Identifying and Comparing Objects