<!--
{
  "availability" : [
    "iOS: 14.0.0 -",
    "iPadOS: 14.0.0 -",
    "macCatalyst: 14.0.0 -",
    "macOS: 11.0.0 -",
    "tvOS: 14.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 7.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/Optional/publisher-swift.property",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Property",
  "symbol" : {
    "kind" : "Instance Property",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:Sq7CombineE9publisherSqAAE9PublisherVyx_Gvp"
  },
  "title" : "publisher"
}
-->

# publisher

A Combine publisher that publishes this instance’s value to each subscriber exactly once, if it has any value at all.

```
var publisher: Optional<Wrapped>.Publisher { get }
```

## Discussion

In the following example, the publisher for an `Int?` optional publishes its value once, then finishes normally:

```
let optional1: Int? = 1
    optional1.publisher
        .sink(receiveCompletion: { print("optional1 completed.") },
              receiveValue: { print("optional1 = \($0)") }
        )

// Prints:
// optional1 = 1.
// optional1 completed.
```

In contrast with the <doc://com.apple.documentation/documentation/Combine/Just> publisher, which always publishes a single value, this publisher might not send any values and instead finish normally if the optional’s `output` is `nil`. In the next example, an `Int?` optional that’s `nil` immediately sends the <doc://com.apple.documentation/documentation/Combine/Subscribers/Completion/finished> completion, without producing any values.

```
let optional2: Int? = nil
optional2.publisher
        .sink(receiveCompletion: { print("optional2 completed.") },
              receiveValue: { print("optional2 = \($0)") }
        )

// Prints:
// optional2 completed.
```

---

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)