!=(_:_:)

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

static func != (lhs: _OptionalNilComparisonType, rhs: borrowing Wrapped?) -> Bool

Parameters

lhs

A nil literal.

rhs

A value to compare to nil.

You can use this not-equal-to operator (!=) to test whether an optional instance is not 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 wraps a value and is therefore not nil.

var stream: DataStream? = fetchDataStream()
if nil != stream {
    print("The data stream has been configured.")
}
// Prints "The data stream has been configured."