Operator: ==

operator == { associativity precedence }

Declarations

func ==(_: (), rhs: ())

Returns a Boolean value indicating whether the corresponding components of two tuples are equal.

All arity zero tuples are equal.

Parameters: lhs: An empty tuple. rhs: An empty tuple.

Declaration

func ==(lhs: (), rhs: ()) -> Bool
func ==(_: Any.Type?, t1: Any.Type?)

Returns a Boolean value indicating whether two types are identical.

Parameters: t0: A type to compare. t1: Another type to compare. Returns: true if both t0 and t1 are nil or if they represent the same type; otherwise, false.

Declaration

func ==(t0: Any.Type?, t1: Any.Type?) -> Bool
func == <A, B, C, D, E, F>(_: (A, B, C, D, E, F), rhs: (A, B, C, D, E, F))

Returns a Boolean value indicating whether the corresponding components of two tuples are equal.

For two tuples to compare as equal, each corresponding pair of components must be equal. The following example compares tuples made up of 6 components:

let a = ("a", 1, 2, 3, 4, 5)
let b = ("a", 1, 2, 3, 4, 5)
print(a == b)
// Prints "true"

let c = ("a", 1, 2, 3, 4, 6)
print(a == c)
// Prints "false"

Parameters: lhs: A tuple of Equatable elements. rhs: Another tuple of elements of the same type as lhs.

Declaration

func ==<A, B, C, D, E, F>(lhs: (A, B, C, D, E, F), rhs: (A, B, C, D, E, F)) -> Bool where A : Equatable, B : Equatable, C : Equatable, D : Equatable, E : Equatable, F : Equatable
func == <A, B, C, D, E>(_: (A, B, C, D, E), rhs: (A, B, C, D, E))

Returns a Boolean value indicating whether the corresponding components of two tuples are equal.

For two tuples to compare as equal, each corresponding pair of components must be equal. The following example compares tuples made up of 5 components:

let a = ("a", 1, 2, 3, 4)
let b = ("a", 1, 2, 3, 4)
print(a == b)
// Prints "true"

let c = ("a", 1, 2, 3, 5)
print(a == c)
// Prints "false"

Parameters: lhs: A tuple of Equatable elements. rhs: Another tuple of elements of the same type as lhs.

Declaration

func ==<A, B, C, D, E>(lhs: (A, B, C, D, E), rhs: (A, B, C, D, E)) -> Bool where A : Equatable, B : Equatable, C : Equatable, D : Equatable, E : Equatable
func == <A, B, C, D>(_: (A, B, C, D), rhs: (A, B, C, D))

Returns a Boolean value indicating whether the corresponding components of two tuples are equal.

For two tuples to compare as equal, each corresponding pair of components must be equal. The following example compares tuples made up of 4 components:

let a = ("a", 1, 2, 3)
let b = ("a", 1, 2, 3)
print(a == b)
// Prints "true"

let c = ("a", 1, 2, 4)
print(a == c)
// Prints "false"

Parameters: lhs: A tuple of Equatable elements. rhs: Another tuple of elements of the same type as lhs.

Declaration

func ==<A, B, C, D>(lhs: (A, B, C, D), rhs: (A, B, C, D)) -> Bool where A : Equatable, B : Equatable, C : Equatable, D : Equatable
func == <A, B, C>(_: (A, B, C), rhs: (A, B, C))

Returns a Boolean value indicating whether the corresponding components of two tuples are equal.

For two tuples to compare as equal, each corresponding pair of components must be equal. The following example compares tuples made up of 3 components:

let a = ("a", 1, 2)
let b = ("a", 1, 2)
print(a == b)
// Prints "true"

let c = ("a", 1, 3)
print(a == c)
// Prints "false"

Parameters: lhs: A tuple of Equatable elements. rhs: Another tuple of elements of the same type as lhs.

Declaration

func ==<A, B, C>(lhs: (A, B, C), rhs: (A, B, C)) -> Bool where A : Equatable, B : Equatable, C : Equatable
func == <A, B>(_: (A, B), rhs: (A, B))

Returns a Boolean value indicating whether the corresponding components of two tuples are equal.

For two tuples to compare as equal, each corresponding pair of components must be equal. The following example compares tuples made up of 2 components:

let a = ("a", 1)
let b = ("a", 1)
print(a == b)
// Prints "true"

let c = ("a", 2)
print(a == c)
// Prints "false"

Parameters: lhs: A tuple of Equatable elements. rhs: Another tuple of elements of the same type as lhs.

Declaration

func ==<A, B>(lhs: (A, B), rhs: (A, B)) -> Bool where A : Equatable, B : Equatable
func == <T>(_: T, rhs: T)

Returns a Boolean value indicating whether the two arguments are equal.

Parameters: lhs: A raw-representable instance. rhs: A second raw-representable instance.

Declaration

func ==<T>(lhs: T, rhs: T) -> Bool where T : RawRepresentable, T.RawValue : Equatable
func ==(_: AnyKeyPath, b: AnyKeyPath)

Returns a Boolean value indicating whether two values are equal.

Equality is the inverse of inequality. For any values a and b, a == b implies that a != b is false.

Parameters: lhs: A value to compare. rhs: Another value to compare.

Declaration

func ==(a: AnyKeyPath, b: AnyKeyPath) -> Bool
func ==(_: [[Element].Element], rhs: [[Element].Element])

Returns a Boolean value indicating whether two arrays contain the same elements in the same order.

You can use the equal-to operator (==) to compare any two arrays that store the same, Equatable-conforming element type.

Parameters: lhs: An array to compare. rhs: Another array to compare.

Declaration

func ==(lhs: [[Element].Element], rhs: [[Element].Element]) -> Bool
func ==(_: [Key : Value], rhs: [Key : Value])

Returns a Boolean value indicating whether two values are equal.

Equality is the inverse of inequality. For any values a and b, a == b implies that a != b is false.

Parameters: lhs: A value to compare. rhs: Another value to compare.

Declaration

func ==(lhs: [Key : Value], rhs: [Key : Value]) -> Bool
func ==(_: _OptionalNilComparisonType, rhs: Wrapped?)

Returns a Boolean value indicating whether the right-hand-side argument is nil.

You can use this equal-to operator (==) to test whether an optional instance is nil even when the wrapped value's type does not conform to the Equatable protocol.

The following example declares the stream variable as an optional instance of a hypothetical DataStream type. Although DataStream is not an Equatable type, this operator allows checking whether stream is nil.

var stream: DataStream? = nil
if nil == stream {
    print("No data stream is configured.")
}
// Prints "No data stream is configured."

Parameters: lhs: A nil literal. rhs: A value to compare to nil.

Declaration

func ==(lhs: _OptionalNilComparisonType, rhs: Wrapped?) -> Bool
func ==(_: AnyHashable, rhs: AnyHashable)

Returns a Boolean value indicating whether two type-erased hashable instances wrap the same type and value.

Two instances of AnyHashable compare as equal if and only if the underlying types have the same conformance to the Equatable protocol and the underlying values compare as equal.

The following example creates two type-erased hashable values: x wraps an Int with the value 42, while y wraps a UInt8 with the same numeric value. Because the underlying types of x and y are different, the two variables do not compare as equal despite having equal underlying values.

let x = AnyHashable(Int(42))
let y = AnyHashable(UInt8(42))

print(x == y)
// Prints "false" because `Int` and `UInt8` are different types

print(x == AnyHashable(Int(42)))
// Prints "true"

Parameters: lhs: A type-erased hashable value. rhs: Another type-erased hashable value.

Declaration

func ==(lhs: AnyHashable, rhs: AnyHashable) -> Bool
func ==(_: AnyIndex, rhs: AnyIndex)

Returns a Boolean value indicating whether two indices wrap equal underlying indices.

The types of the two underlying indices must be identical.

Parameters: lhs: An index to compare. rhs: Another index to compare.

Declaration

func ==(lhs: AnyIndex, rhs: AnyIndex) -> Bool
func ==(_: ArraySlice<ArraySlice<Element>.Element>, rhs: ArraySlice<ArraySlice<Element>.Element>)

Returns a Boolean value indicating whether two arrays contain the same elements in the same order.

You can use the equal-to operator (==) to compare any two arrays that store the same, Equatable-conforming element type.

Parameters: lhs: An array to compare. rhs: Another array to compare.

Declaration

func ==(lhs: ArraySlice<ArraySlice<Element>.Element>, rhs: ArraySlice<ArraySlice<Element>.Element>) -> Bool
func ==(_: AutoreleasingUnsafeMutablePointer<Pointee>, rhs: AutoreleasingUnsafeMutablePointer<Pointee>)

Returns a Boolean value indicating whether two values are equal.

Equality is the inverse of inequality. For any values a and b, a == b implies that a != b is false.

Parameters: lhs: A value to compare. rhs: Another value to compare.

Declaration

func ==(lhs: AutoreleasingUnsafeMutablePointer<Pointee>, rhs: AutoreleasingUnsafeMutablePointer<Pointee>) -> Bool
func ==(_: Bool, rhs: Bool)

Returns a Boolean value indicating whether two values are equal.

Equality is the inverse of inequality. For any values a and b, a == b implies that a != b is false.

Parameters: lhs: A value to compare. rhs: Another value to compare.

Declaration

func ==(lhs: Bool, rhs: Bool) -> Bool
func ==(_: Character, rhs: Character)

Returns a Boolean value indicating whether two values are equal.

Equality is the inverse of inequality. For any values a and b, a == b implies that a != b is false.

Parameters: lhs: A value to compare. rhs: Another value to compare.

Declaration

func ==(lhs: Character, rhs: Character) -> Bool
func ==(_: Character.UnicodeScalarView.Index, rhs: Character.UnicodeScalarView.Index)

Returns a Boolean value indicating whether two values are equal.

Equality is the inverse of inequality. For any values a and b, a == b implies that a != b is false.

Parameters: lhs: A value to compare. rhs: Another value to compare.

Declaration

func ==(lhs: Character.UnicodeScalarView.Index, rhs: Character.UnicodeScalarView.Index) -> Bool
func ==(_: ClosedRange<Bound>, rhs: ClosedRange<Bound>)

Returns a Boolean value indicating whether two ranges are equal.

Two ranges are equal when they have the same lower and upper bounds.

let x: ClosedRange = 5...15
print(x == 5...15)
// Prints "true"
print(x == 10...20)
// Prints "false"

Parameters: lhs: A range to compare. rhs: Another range to compare.

Declaration

func ==(lhs: ClosedRange<Bound>, rhs: ClosedRange<Bound>) -> Bool
func ==(_: ClosedRange<Bound>.Index, rhs: ClosedRange<Bound>.Index)

Returns a Boolean value indicating whether two values are equal.

Equality is the inverse of inequality. For any values a and b, a == b implies that a != b is false.

Parameters: lhs: A value to compare. rhs: Another value to compare.

Declaration

func ==(lhs: ClosedRange<Bound>.Index, rhs: ClosedRange<Bound>.Index) -> Bool
func ==(_: CodingUserInfoKey, rhs: CodingUserInfoKey)

Returns a Boolean value indicating whether the given keys are equal.

lhs: The key to compare against.

rhs: The key to compare with.

Declaration

func ==(lhs: CodingUserInfoKey, rhs: CodingUserInfoKey) -> Bool
func ==(_: ContiguousArray<ContiguousArray<Element>.Element>, rhs: ContiguousArray<ContiguousArray<Element>.Element>)

Returns a Boolean value indicating whether two arrays contain the same elements in the same order.

You can use the equal-to operator (==) to compare any two arrays that store the same, Equatable-conforming element type.

Parameters: lhs: An array to compare. rhs: Another array to compare.

Declaration

func ==(lhs: ContiguousArray<ContiguousArray<Element>.Element>, rhs: ContiguousArray<ContiguousArray<Element>.Element>) -> Bool
func ==(_: Dictionary<Key, Value>.Index, rhs: Dictionary<Key, Value>.Index)

Returns a Boolean value indicating whether two values are equal.

Equality is the inverse of inequality. For any values a and b, a == b implies that a != b is false.

Parameters: lhs: A value to compare. rhs: Another value to compare.

Declaration

func ==(lhs: Dictionary<Key, Value>.Index, rhs: Dictionary<Key, Value>.Index) -> Bool
func ==(_: Dictionary<Key, Value>.Keys, rhs: Dictionary<Key, Value>.Keys)

Returns a Boolean value indicating whether two values are equal.

Equality is the inverse of inequality. For any values a and b, a == b implies that a != b is false.

Parameters: lhs: A value to compare. rhs: Another value to compare.

Declaration

func ==(lhs: Dictionary<Key, Value>.Keys, rhs: Dictionary<Key, Value>.Keys) -> Bool
func ==(_: EmptyCollection<Element>, rhs: EmptyCollection<Element>)

Returns a Boolean value indicating whether two values are equal.

Equality is the inverse of inequality. For any values a and b, a == b implies that a != b is false.

Parameters: lhs: A value to compare. rhs: Another value to compare.

Declaration

func ==(lhs: EmptyCollection<Element>, rhs: EmptyCollection<Element>) -> Bool
func ==(_: FlattenCollection<Base>.Index, rhs: FlattenCollection<Base>.Index)

Returns a Boolean value indicating whether two values are equal.

Equality is the inverse of inequality. For any values a and b, a == b implies that a != b is false.

Parameters: lhs: A value to compare. rhs: Another value to compare.

Declaration

func ==(lhs: FlattenCollection<Base>.Index, rhs: FlattenCollection<Base>.Index) -> Bool
func ==(_: Int, rhs: Int)

Returns a Boolean value indicating whether two values are equal.

Equality is the inverse of inequality. For any values a and b, a == b implies that a != b is false.

Parameters: lhs: A value to compare. rhs: Another value to compare.

Declaration

func ==(lhs: Int, rhs: Int) -> Bool

Declared In

Int, FixedWidthInteger
func ==(_: Int8, rhs: Int8)

Returns a Boolean value indicating whether two values are equal.

Equality is the inverse of inequality. For any values a and b, a == b implies that a != b is false.

Parameters: lhs: A value to compare. rhs: Another value to compare.

Declaration

func ==(lhs: Int8, rhs: Int8) -> Bool

Declared In

Int8, FixedWidthInteger
func ==(_: Int16, rhs: Int16)

Returns a Boolean value indicating whether two values are equal.

Equality is the inverse of inequality. For any values a and b, a == b implies that a != b is false.

Parameters: lhs: A value to compare. rhs: Another value to compare.

Declaration

func ==(lhs: Int16, rhs: Int16) -> Bool

Declared In

Int16, FixedWidthInteger
func ==(_: Int32, rhs: Int32)

Returns a Boolean value indicating whether two values are equal.

Equality is the inverse of inequality. For any values a and b, a == b implies that a != b is false.

Parameters: lhs: A value to compare. rhs: Another value to compare.

Declaration

func ==(lhs: Int32, rhs: Int32) -> Bool

Declared In

Int32, FixedWidthInteger
func ==(_: Int64, rhs: Int64)

Returns a Boolean value indicating whether two values are equal.

Equality is the inverse of inequality. For any values a and b, a == b implies that a != b is false.

Parameters: lhs: A value to compare. rhs: Another value to compare.

Declaration

func ==(lhs: Int64, rhs: Int64) -> Bool

Declared In

Int64, FixedWidthInteger
func ==(_: LazyDropWhileCollection<Base>.Index, rhs: LazyDropWhileCollection<Base>.Index)

Returns a Boolean value indicating whether two values are equal.

Equality is the inverse of inequality. For any values a and b, a == b implies that a != b is false.

Parameters: lhs: A value to compare. rhs: Another value to compare.

Declaration

func ==(lhs: LazyDropWhileCollection<Base>.Index, rhs: LazyDropWhileCollection<Base>.Index) -> Bool
func ==(_: LazyPrefixWhileCollection<Base>.Index, rhs: LazyPrefixWhileCollection<Base>.Index)

Returns a Boolean value indicating whether two values are equal.

Equality is the inverse of inequality. For any values a and b, a == b implies that a != b is false.

Parameters: lhs: A value to compare. rhs: Another value to compare.

Declaration

func ==(lhs: LazyPrefixWhileCollection<Base>.Index, rhs: LazyPrefixWhileCollection<Base>.Index) -> Bool
func ==(_: ManagedBufferPointer<Header, Element>, rhs: ManagedBufferPointer<Header, Element>)

Returns a Boolean value indicating whether two values are equal.

Equality is the inverse of inequality. For any values a and b, a == b implies that a != b is false.

Parameters: lhs: A value to compare. rhs: Another value to compare.

Declaration

func ==(lhs: ManagedBufferPointer<Header, Element>, rhs: ManagedBufferPointer<Header, Element>) -> Bool
func ==(_: OpaquePointer, rhs: OpaquePointer)

Returns a Boolean value indicating whether two values are equal.

Equality is the inverse of inequality. For any values a and b, a == b implies that a != b is false.

Parameters: lhs: A value to compare. rhs: Another value to compare.

Declaration

func ==(lhs: OpaquePointer, rhs: OpaquePointer) -> Bool
func ==(_: Range<Range<Bound>.Bound>, rhs: Range<Range<Bound>.Bound>)

Returns a Boolean value indicating whether two ranges are equal.

Two ranges are equal when they have the same lower and upper bounds. That requirement holds even for empty ranges.

let x: Range = 5..<15
print(x == 5..<15)
// Prints "true"

let y: Range = 5..<5
print(y == 15..<15)
// Prints "false"

Parameters: lhs: A range to compare. rhs: Another range to compare.

Declaration

func ==(lhs: Range<Range<Bound>.Bound>, rhs: Range<Range<Bound>.Bound>) -> Bool
func ==(_: ReversedCollection<Base>.Index, rhs: ReversedCollection<Base>.Index)

Returns a Boolean value indicating whether two values are equal.

Equality is the inverse of inequality. For any values a and b, a == b implies that a != b is false.

Parameters: lhs: A value to compare. rhs: Another value to compare.

Declaration

func ==(lhs: ReversedCollection<Base>.Index, rhs: ReversedCollection<Base>.Index) -> Bool
func ==(_: Self, rhs: Self)

Returns a Boolean value indicating whether two values are equal.

Equality is the inverse of inequality. For any values a and b, a == b implies that a != b is false.

Parameters: lhs: A value to compare. rhs: Another value to compare.

Declaration

func ==(lhs: Self, rhs: Self) -> Bool

Declared In

BinaryFloatingPoint, FloatingPoint
func ==(_: Set<Element>, rhs: Set<Element>)

Returns a Boolean value indicating whether two sets have equal elements.

Parameters: lhs: A set. rhs: Another set. Returns: true if the lhs and rhs have the same elements; otherwise, false.

Declaration

func ==(lhs: Set<Element>, rhs: Set<Element>) -> Bool
func ==(_: Set<Element>.Index, rhs: Set<Element>.Index)

Returns a Boolean value indicating whether two values are equal.

Equality is the inverse of inequality. For any values a and b, a == b implies that a != b is false.

Parameters: lhs: A value to compare. rhs: Another value to compare.

Declaration

func ==(lhs: Set<Element>.Index, rhs: Set<Element>.Index) -> Bool
func ==(_: String, rhs: String)

Returns a Boolean value indicating whether two values are equal.

Equality is the inverse of inequality. For any values a and b, a == b implies that a != b is false.

Parameters: lhs: A value to compare. rhs: Another value to compare.

Declaration

func ==(lhs: String, rhs: String) -> Bool
func ==(_: String.Index, rhs: String.Index)

Returns a Boolean value indicating whether two values are equal.

Equality is the inverse of inequality. For any values a and b, a == b implies that a != b is false.

Parameters: lhs: A value to compare. rhs: Another value to compare.

Declaration

func ==(lhs: String.Index, rhs: String.Index) -> Bool
func ==(_: UInt, rhs: UInt)

Returns a Boolean value indicating whether two values are equal.

Equality is the inverse of inequality. For any values a and b, a == b implies that a != b is false.

Parameters: lhs: A value to compare. rhs: Another value to compare.

Declaration

func ==(lhs: UInt, rhs: UInt) -> Bool

Declared In

UInt, FixedWidthInteger
func ==(_: UInt8, rhs: UInt8)

Returns a Boolean value indicating whether two values are equal.

Equality is the inverse of inequality. For any values a and b, a == b implies that a != b is false.

Parameters: lhs: A value to compare. rhs: Another value to compare.

Declaration

func ==(lhs: UInt8, rhs: UInt8) -> Bool

Declared In

UInt8, FixedWidthInteger
func ==(_: UInt16, rhs: UInt16)

Returns a Boolean value indicating whether two values are equal.

Equality is the inverse of inequality. For any values a and b, a == b implies that a != b is false.

Parameters: lhs: A value to compare. rhs: Another value to compare.

Declaration

func ==(lhs: UInt16, rhs: UInt16) -> Bool

Declared In

UInt16, FixedWidthInteger
func ==(_: UInt32, rhs: UInt32)

Returns a Boolean value indicating whether two values are equal.

Equality is the inverse of inequality. For any values a and b, a == b implies that a != b is false.

Parameters: lhs: A value to compare. rhs: Another value to compare.

Declaration

func ==(lhs: UInt32, rhs: UInt32) -> Bool

Declared In

UInt32, FixedWidthInteger
func ==(_: UInt64, rhs: UInt64)

Returns a Boolean value indicating whether two values are equal.

Equality is the inverse of inequality. For any values a and b, a == b implies that a != b is false.

Parameters: lhs: A value to compare. rhs: Another value to compare.

Declaration

func ==(lhs: UInt64, rhs: UInt64) -> Bool

Declared In

UInt64, FixedWidthInteger
func ==(_: Unicode.Scalar, rhs: Unicode.Scalar)

Returns a Boolean value indicating whether two values are equal.

Equality is the inverse of inequality. For any values a and b, a == b implies that a != b is false.

Parameters: lhs: A value to compare. rhs: Another value to compare.

Declaration

func ==(lhs: Unicode.Scalar, rhs: Unicode.Scalar) -> Bool
func ==(_: UnicodeDecodingResult, rhs: UnicodeDecodingResult)

Returns a Boolean value indicating whether two values are equal.

Equality is the inverse of inequality. For any values a and b, a == b implies that a != b is false.

Parameters: lhs: A value to compare. rhs: Another value to compare.

Declaration

func ==(lhs: UnicodeDecodingResult, rhs: UnicodeDecodingResult) -> Bool
func ==(_: UnsafeMutablePointer<Pointee>, rhs: UnsafeMutablePointer<Pointee>)

Returns a Boolean value indicating whether two pointers are equal.

Parameters: lhs: A pointer. rhs: Another pointer. Returns: true if lhs and rhs reference the same memory address; otherwise, false.

Declaration

func ==(lhs: UnsafeMutablePointer<Pointee>, rhs: UnsafeMutablePointer<Pointee>) -> Bool
func ==(_: UnsafeMutableRawPointer, rhs: UnsafeMutableRawPointer)

Returns a Boolean value indicating whether two pointers are equal.

Parameters: lhs: A pointer. rhs: Another pointer. Returns: true if lhs and rhs reference the same memory address; otherwise, false.

Declaration

func ==(lhs: UnsafeMutableRawPointer, rhs: UnsafeMutableRawPointer) -> Bool
func ==(_: UnsafePointer<Pointee>, rhs: UnsafePointer<Pointee>)

Returns a Boolean value indicating whether two pointers are equal.

Parameters: lhs: A pointer. rhs: Another pointer. Returns: true if lhs and rhs reference the same memory address; otherwise, false.

Declaration

func ==(lhs: UnsafePointer<Pointee>, rhs: UnsafePointer<Pointee>) -> Bool
func ==(_: UnsafeRawPointer, rhs: UnsafeRawPointer)

Returns a Boolean value indicating whether two pointers are equal.

Parameters: lhs: A pointer. rhs: Another pointer. Returns: true if lhs and rhs reference the same memory address; otherwise, false.

Declaration

func ==(lhs: UnsafeRawPointer, rhs: UnsafeRawPointer) -> Bool
func ==(_: Wrapped?, rhs: _OptionalNilComparisonType)

Returns a Boolean value indicating whether the left-hand-side argument is nil.

You can use this equal-to operator (==) to test whether an optional instance is nil even when the wrapped value's type does not conform to the Equatable protocol.

The following example declares the stream variable as an optional instance of a hypothetical DataStream type. Although DataStream is not an Equatable type, this operator allows checking whether stream is nil.

var stream: DataStream? = nil
if stream == nil {
    print("No data stream is configured.")
}
// Prints "No data stream is configured."

Parameters: lhs: A value to compare to nil. rhs: A nil literal.

Declaration

func ==(lhs: Wrapped?, rhs: _OptionalNilComparisonType) -> Bool
func ==(_: Wrapped?, rhs: Wrapped?)

Returns a Boolean value indicating whether two optional instances are equal.

Use this equal-to operator (==) to compare any two optional instances of a type that conforms to the Equatable protocol. The comparison returns true if both arguments are nil or if the two arguments wrap values that are equal. Conversely, the comparison returns false if only one of the arguments is nil or if the two arguments wrap values that are not equal.

let group1 = [1, 2, 3, 4, 5]
let group2 = [1, 3, 5, 7, 9]
if group1.first == group2.first {
    print("The two groups start the same.")
}
// Prints "The two groups start the same."

You can also use this operator to compare a non-optional value to an optional that wraps the same type. The non-optional value is wrapped as an optional before the comparison is made. In the following example, the numberToMatch constant is wrapped as an optional before comparing to the optional numberFromString:

let numberToFind: Int = 23
let numberFromString: Int? = Int("23")      // Optional(23)
if numberToFind == numberFromString {
    print("It's a match!")
}
// Prints "It's a match!"

An instance that is expressed as a literal can also be used with this operator. In the next example, an integer literal is compared with the optional integer numberFromString. The literal 23 is inferred as an Int instance and then wrapped as an optional before the comparison is performed.

if 23 == numberFromString {
    print("It's a match!")
}
// Prints "It's a match!"

Parameters: lhs: An optional value to compare. rhs: Another optional value to compare.

Declaration

func ==(lhs: Wrapped?, rhs: Wrapped?) -> Bool
func ==(_: ObjectIdentifier, y: ObjectIdentifier)

Returns a Boolean value indicating whether two values are equal.

Equality is the inverse of inequality. For any values a and b, a == b implies that a != b is false.

Parameters: lhs: A value to compare. rhs: Another value to compare.

Declaration

func ==(x: ObjectIdentifier, y: ObjectIdentifier) -> Bool
func ==(_: Self, y: Self)

Declaration

func ==(x: Self, y: Self) -> Bool

Declared In

Strideable
func ==(_: Self, y: Self)

Declaration

func ==(x: Self, y: Self) -> Bool

Declared In

FixedWidthInteger
func ==(_: Self, y: Self)

Declaration

func ==(x: Self, y: Self) -> Bool

Declared In

Strideable
func ==(_: Self, y: Self)

Declaration

func ==(x: Self, y: Self) -> Bool

Declared In

FixedWidthInteger
func ==(_: Self, y: Self)

Declaration

func ==(x: Self, y: Self) -> Bool

Declared In

FixedWidthInteger
func ==(_: Self, y: Self)

Declaration

func ==(x: Self, y: Self) -> Bool

Declared In

Strideable
func ==(_: Self, y: Self)

Declaration

func ==(x: Self, y: Self) -> Bool

Declared In

FixedWidthInteger
func ==(_: Self, y: Self)

Declaration

func ==(x: Self, y: Self) -> Bool

Declared In

BinaryFloatingPoint, Strideable
func ==(_: Self, y: Self)

Declaration

func ==(x: Self, y: Self) -> Bool

Declared In

Strideable
func ==(_: Self, y: Self)

Declaration

func ==(x: Self, y: Self) -> Bool

Declared In

FixedWidthInteger
func ==(_: Self, y: Self)

Declaration

func ==(x: Self, y: Self) -> Bool

Declared In

FixedWidthInteger
func ==(_: Self, y: Self)

Declaration

func ==(x: Self, y: Self) -> Bool

Declared In

FixedWidthInteger
func ==(_: Self, y: Self)

Declaration

func ==(x: Self, y: Self) -> Bool

Declared In

FixedWidthInteger
func ==(_: Self, y: Self)

Declaration

func ==(x: Self, y: Self) -> Bool

Declared In

FixedWidthInteger
func ==(_: Self, y: Self)

Declaration

func ==(x: Self, y: Self) -> Bool

Declared In

FixedWidthInteger
func ==(_: Self, y: Self)

Declaration

func ==(x: Self, y: Self) -> Bool

Declared In

Strideable
func == <S>(_: Self, rhs: S)

Returns a Boolean value indicating whether two values are equal.

Equality is the inverse of inequality. For any values a and b, a == b implies that a != b is false.

Parameters: lhs: A value to compare. rhs: Another value to compare.

Declaration

func ==<S>(lhs: Self, rhs: S) -> Bool where S : StringProtocol

Declared In

StringProtocol