---
title: makeConnectable()
framework: combine
role: symbol
role_heading: Instance Method
path: combine/publisher/makeconnectable()
---

# makeConnectable()

Creates a connectable wrapper around the publisher.

## Declaration

```swift
func makeConnectable() -> Publishers.MakeConnectable<Self>
```

## Mentioned in

Controlling Publishing with Connectable Publishers

## Return Value

Return Value A ConnectablePublisher wrapping this publisher.

## Discussion

Discussion In the following example, makeConnectable() wraps its upstream publisher (an instance of Publishers.Share) with a ConnectablePublisher. Without this, the first sink subscriber would receive all the elements from the sequence publisher and cause it to complete before the second subscriber attaches. By making the publisher connectable, the publisher doesn’t produce any elements until after the connect() call.  let subject = Just<String>("Sent")  let pub = subject      .share()      .makeConnectable()  cancellable1 = pub.sink { print ("Stream 1 received: \($0)")  }

// For example purposes, use DispatchQueue to add a second subscriber  // a second later, and then connect to the publisher a second after that.  DispatchQueue.main.asyncAfter(deadline: .now() + 1) {      self.cancellable2 = pub.sink { print ("Stream 2 received: \($0)") }  }  DispatchQueue.main.asyncAfter(deadline: .now() + 2) {      self.connectable = pub.connect()  }  // Prints:  // Stream 2 received: Sent  // Stream 1 received: Sent note: The connect() operator returns a Cancellable instance that you must retain. You can also use this instance to cancel publishing.
