---
title: "sink(receiveValue:)"
framework: combine
role: symbol
role_heading: Instance Method
path: "combine/publisher/sink(receivevalue:)"
---

# sink(receiveValue:)

Attaches a subscriber with closure-based behavior to a publisher that never fails.

## Declaration

```swift
func sink(receiveValue: @escaping (Self.Output) -> Void) -> AnyCancellable
```

## Parameters

- `receiveValue`: The closure to execute on receipt of a value.

## Mentioned in

Processing Published Elements with Subscribers Using Combine for Your App’s Asynchronous Code Controlling Publishing with Connectable Publishers Replacing Foundation Timers with Timer Publishers

## Return 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

Discussion Use sink(receiveValue:) to observe values received by the publisher and print them to the console. This operator can only be used when the stream doesn’t fail, that is, when the publisher’s Failure type is Never. In this example, a Range publisher publishes integers to a sink(receiveValue:) operator’s receiveValue closure that prints them to the console: let integers = (0...3) integers.publisher     .sink { print("Received \($0)") }

// Prints: //  Received 0 //  Received 1 //  Received 2 //  Received 3 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.

## See Also

### Connecting simple subscribers

- [assign(to:on:)](combine/publisher/assign(to:on:).md)
- [assign(to:)](combine/publisher/assign(to:).md)
- [sink(receiveCompletion:receiveValue:)](combine/publisher/sink(receivecompletion:receivevalue:).md)
