<!--
{
  "availability" : [
    "iOS: 13.0.0 -",
    "iPadOS: 13.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.15.0 -",
    "tvOS: 13.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 6.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Combine",
  "identifier" : "/documentation/Combine/Publisher/sink(receiveCompletion:receiveValue:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Combine"
    ],
    "preciseIdentifier" : "s:7Combine9PublisherPAAE4sink17receiveCompletion0D5ValueAA14AnyCancellableCyAA11SubscribersO0E0Oy_7FailureQzGc_y6OutputQzctF"
  },
  "title" : "sink(receiveCompletion:receiveValue:)"
}
-->

# sink(receiveCompletion:receiveValue:)

Attaches a subscriber with closure-based behavior.

```
func sink(receiveCompletion: @escaping (Subscribers.Completion<Self.Failure>) -> Void, receiveValue: @escaping (Self.Output) -> Void) -> AnyCancellable
```

## Parameters

`receiveValue`

The closure to execute on receipt of a value.

## Return Value

A cancellable instance, which you use when you end assignment of the received value. Deallocation of the result will tear down the subscription stream.

## Discussion

Use [`sink(receiveCompletion:receiveValue:)`](/documentation/Combine/Publisher/sink(receiveCompletion:receiveValue:)) to observe values received by the publisher and process them using a closure you specify.

In this example, a <doc://com.apple.documentation/documentation/Swift/Range> publisher publishes integers to a [`sink(receiveCompletion:receiveValue:)`](/documentation/Combine/Publisher/sink(receiveCompletion:receiveValue:)) operator’s `receiveValue` closure that prints them to the console. Upon completion the [`sink(receiveCompletion:receiveValue:)`](/documentation/Combine/Publisher/sink(receiveCompletion:receiveValue:)) operator’s `receiveCompletion` closure indicates the successful termination of the stream.

```
let myRange = (0...3)
cancellable = myRange.publisher
    .sink(receiveCompletion: { print ("completion: \($0)") },
          receiveValue: { print ("value: \($0)") })

// Prints:
//  value: 0
//  value: 1
//  value: 2
//  value: 3
//  completion: finished
```

This method creates the subscriber and immediately requests an unlimited number of values, prior to returning the subscriber.
The return value should be held, otherwise the stream will be canceled.

---

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)