<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.10.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/Optional/!=(_:_:)-9e46a",
  "metadataVersion" : "0.1.0",
  "role" : "Operator",
  "symbol" : {
    "kind" : "Operator",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:SqsRi_zRi0_zrlE2neoiySbxSg_s26_OptionalNilComparisonTypeVtFZ"
  },
  "title" : "!=(_:_:)"
}
-->

# !=(_:_:)

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

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

## Parameters

`lhs`

A value to compare to `nil`.

`rhs`

A `nil` literal.

## Discussion

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 stream != nil {
    print("The data stream has been configured.")
}
// Prints "The data stream has been configured."
```

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)