operator
== {
associativity
precedence
}
Declarations
Returns true
iff t0
is identical to t1
; i.e. if they are both
nil
or they both represent the same type.
Declaration
func
==(
t0
:
Any
.
Type
?,
t1
:
Any
.
Type
?) -
>
Bool
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
)
(
a
==
b
)
// Prints "true"
let
c
= (
"a"
,
2
)
(
a
==
c
)
// Prints "false"
Parameters:
lhs: A tuple of Equatable
elements.
rhs: Another tuple of elements of the same type as lhs
.
Declaration
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
)
(
a
==
b
)
// Prints "true"
let
c
= (
"a"
,
1
,
3
)
(
a
==
c
)
// Prints "false"
Parameters:
lhs: A tuple of Equatable
elements.
rhs: Another tuple of elements of the same type as lhs
.
Declaration
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
)
(
a
==
b
)
// Prints "true"
let
c
= (
"a"
,
1
,
2
,
4
)
(
a
==
c
)
// Prints "false"
Parameters:
lhs: A tuple of Equatable
elements.
rhs: Another tuple of elements of the same type as lhs
.
Declaration
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
)
(
a
==
b
)
// Prints "true"
let
c
= (
"a"
,
1
,
2
,
3
,
5
)
(
a
==
c
)
// Prints "false"
Parameters:
lhs: A tuple of Equatable
elements.
rhs: Another tuple of elements of the same type as lhs
.
Declaration
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
)
(
a
==
b
)
// Prints "true"
let
c
= (
"a"
,
1
,
2
,
3
,
4
,
6
)
(
a
==
c
)
// Prints "false"
Parameters:
lhs: A tuple of Equatable
elements.
rhs: Another tuple of elements of the same type as lhs
.
Declaration
Declaration
func
==
<
Base
where
Base
:
Collection
>
(
lhs
:
LazyDropWhileIndex
<
Base
>
,
rhs
:
LazyDropWhileIndex
<
Base
>
) -
>
Bool
Declaration
func
==
<
Base
where
Base
:
Collection
>
(
lhs
:
LazyPrefixWhileIndex
<
Base
>
,
rhs
:
LazyPrefixWhileIndex
<
Base
>
) -
>
Bool
Returns true
if these arrays contain the same elements.
Declaration
func
==
<
Element
where
Element
:
Equatable
>
(
lhs
:
ArraySlice
<
Element
>
,
rhs
:
ArraySlice
<
Element
>
) -
>
Bool
Returns true
if these arrays contain the same elements.
Declaration
func
==
<
Element
where
Element
:
Equatable
>
(
lhs
:
ContiguousArray
<
Element
>
,
rhs
:
ContiguousArray
<
Element
>
) -
>
Bool
Declaration
func
==
<
Header
,
Element
>
(
lhs
:
ManagedBufferPointer
<
Header
,
Element
>
,
rhs
:
ManagedBufferPointer
<
Header
,
Element
>
) -
>
Bool
Declaration
func
==
<
Pointee
>
(
lhs
:
AutoreleasingUnsafeMutablePointer
<
Pointee
>
,
rhs
:
AutoreleasingUnsafeMutablePointer
<
Pointee
>
) -
>
Bool
Declaration
func
==
<
T
where
T
:
BinaryInteger
>
(
lhs
:
T
,
rhs
:
T
) -
>
Bool
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
{
(
"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
:
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
{
(
"It's a match!"
)
}
// Prints "It's a match!"
Parameters: lhs: An optional value to compare. rhs: Another optional value to compare.
Declaration
Declaration
func
==
<
T
where
T
:
FloatingPoint
>
(
lhs
:
T
,
rhs
:
T
) -
>
Bool
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
where
T
:
RawRepresentable
,
T
.
RawValue
:
Equatable
>
(
lhs
:
T
,
rhs
:
T
) -
>
Bool
Declaration
func
==
<
T
where
T
:
Strideable
>
(
x
:
T
,
y
:
T
) -
>
Bool
Declaration
func
==
<
T
,
U
where
T
:
BinaryInteger
,
U
:
BinaryInteger
>
(
lhs
:
T
,
rhs
:
U
) -
>
Bool
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
{
(
"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
==
<
T
>
(
lhs
:
_OptionalNilComparisonType
,
rhs
:
T
?) -
>
Bool
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
{
(
"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
==
<
T
>
(
lhs
:
T
?,
rhs
:
_OptionalNilComparisonType
) -
>
Bool
Declaration
func
==
<
Value
,
Element
>
(
lhs
:
_HeapBuffer
<
Value
,
Element
>
,
rhs
:
_HeapBuffer
<
Value
,
Element
>
) -
>
Bool
Returns a Boolean value that indicates whether the two arguments have equal values.
See Also:
Equatable
,Comparable
Declaration
func
==(
lhs
:
Int
,
rhs
:
Int
) -
>
Bool