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

# sink(receiveCompletion:receiveValue:)

Attaches a subscriber with closure-based behavior.

## Declaration

```swift
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.

## Mentioned in

Receiving and Handling Events with Combine

## 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(receiveCompletion:receiveValue:) to observe values received by the publisher and process them using a closure you specify. In this example, a Range publisher publishes integers to a sink(receiveCompletion:receiveValue:) operator’s receiveValue closure that prints them to the console. Upon completion the 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.

## See Also

### Connecting simple subscribers

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