<!--
{
  "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/ConnectablePublisher/autoconnect()",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Combine"
    ],
    "preciseIdentifier" : "s:7Combine20ConnectablePublisherPAAE11autoconnectAA10PublishersO11AutoconnectCy_xGyF"
  },
  "title" : "autoconnect()"
}
-->

# autoconnect()

Automates the process of connecting or disconnecting from this connectable publisher.

```
func autoconnect() -> Publishers.Autoconnect<Self>
```

## Return Value

A publisher which automatically connects to its upstream connectable publisher.

## Discussion

Use [`autoconnect()`](/documentation/Combine/ConnectablePublisher/autoconnect()) to simplify working with [`ConnectablePublisher`](/documentation/Combine/ConnectablePublisher) instances, such as <doc://com.apple.documentation/documentation/Foundation/Timer/TimerPublisher> in the Foundation framework.

In the following example, the <doc://com.apple.documentation/documentation/Foundation/Timer/publish(every:tolerance:on:in:options:)> operator creates a <doc://com.apple.documentation/documentation/Foundation/Timer/TimerPublisher>, which is a [`ConnectablePublisher`](/documentation/Combine/ConnectablePublisher). As a result, subscribers don’t receive any values until after a call to [`connect()`](/documentation/Combine/ConnectablePublisher/connect()).
For convenience when working with a single subscriber, the [`autoconnect()`](/documentation/Combine/ConnectablePublisher/autoconnect()) operator performs the [`connect()`](/documentation/Combine/ConnectablePublisher/connect()) call when attached to by the subscriber.

```
cancellable = Timer.publish(every: 1, on: .main, in: .default)
    .autoconnect()
    .sink { date in
        print ("Date now: \(date)")
    }
```

---

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)