---
title: Publisher
framework: combine
role: symbol
role_heading: Protocol
path: combine/publisher
---

# Publisher

Declares that a type can transmit a sequence of values over time.

## Declaration

```swift
protocol Publisher<Output, Failure>
```

## Mentioned in

Processing Published Elements with Subscribers Receiving and Handling Events with Combine Using Combine for Your App’s Asynchronous Code

## Overview

Overview A publisher delivers elements to one or more Subscriber instances. The subscriber’s Input and Failure associated types must match the Output and Failure types declared by the publisher. The publisher implements the receive(subscriber:)method to accept a subscriber. After this, the publisher can call the following methods on the subscriber: receive(subscription:): Acknowledges the subscribe request and returns a Subscription instance. The subscriber uses the subscription to demand elements from the publisher and can use it to cancel publishing. receive(_:): Delivers one element from the publisher to the subscriber. receive(completion:): Informs the subscriber that publishing has ended, either normally or with an error. Every Publisher must adhere to this contract for downstream subscribers to function correctly. tip: A Combine publisher fills a role similar to, but distinct from, the AsyncSequence in the Swift standard library. A Publisher and an AsyncSequence both produce elements over time. However, the pull model in Combine uses a Subscriber to request elements from a publisher, while Swift concurrency uses the for-await-in syntax to iterate over elements published by an AsyncSequence. Both APIs offer methods to modify the sequence by mapping or filtering elements, while only Combine provides time-based operations like debounce(for:scheduler:options:) and throttle(for:scheduler:latest:), and combining operations like merge(with:) and combineLatest(_:_:). To bridge the two approaches, the property values exposes a publisher’s elements as an AsyncSequence, allowing you to iterate over them with for-await-in rather than attaching a Subscriber. Using operators Extensions on Publisher define a wide variety of operators that you compose to create sophisticated event-processing chains. Each operator returns a type that implements the Publisher protocol Most of these types exist as extensions on the Publishers enumeration. For example, the map(_:) operator returns an instance of Publishers.Map. Use operators to assemble a chain of republishers, optionally ending with a subscriber, that processes elements produced by upstream publishers. Each operator creates and configures an instance of a Publisher or Subscriber, and subscribes it to the publisher that you call the method on. In the following example, a sequence publisher emits the integers 1, 2, 3, 4, and 5. A filter(_:) operator creates a Publishers.Filter publisher to only republish even values. A second operator creates a Subscribers.Sink subscriber to print out each value received. The sink subscriber automatically subscribes to the filter publisher, at which point the filter publisher subscribes to its upstream publisher, the sequence publisher. let cancellable = [1, 2, 3, 4, 5].publisher     .filter {         $0 % 2 == 0     }     .sink {         print ("Even number: \($0)")     } // Prints: // Even number: 2 // Even number: 4 Creating Your Own Publishers Rather than implementing the Publisher protocol yourself, you can create your own publisher by using one of several types provided by the Combine framework: Use a concrete subclass of Subject, such as PassthroughSubject, to publish values on-demand by calling its send(_:) method. Use a CurrentValueSubject to publish whenever you update the subject’s underlying value. Add the @Published annotation to a property of one of your own types. In doing so, the property gains a publisher that emits an event whenever the property’s value changes. See the Published type for an example of this approach.

## Topics

### Declaring supporting types

- [Output](combine/publisher/output.md)
- [Failure](combine/publisher/failure.md)

### Working with subscribers

- [receive(subscriber:)](combine/publisher/receive(subscriber:).md)
- [subscribe(_:)](combine/publisher/subscribe(_:)-4u8kn.md)
- [subscribe(_:)](combine/publisher/subscribe(_:)-3fk20.md)

### Mapping elements

- [map(_:)](combine/publisher/map(_:)-99evh.md)
- [tryMap(_:)](combine/publisher/trymap(_:).md)
- [mapError(_:)](combine/publisher/maperror(_:).md)
- [replaceNil(with:)](combine/publisher/replacenil(with:).md)
- [scan(_:_:)](combine/publisher/scan(_:_:).md)
- [tryScan(_:_:)](combine/publisher/tryscan(_:_:).md)
- [setFailureType(to:)](combine/publisher/setfailuretype(to:).md)

### Filtering elements

- [filter(_:)](combine/publisher/filter(_:).md)
- [tryFilter(_:)](combine/publisher/tryfilter(_:).md)
- [compactMap(_:)](combine/publisher/compactmap(_:).md)
- [tryCompactMap(_:)](combine/publisher/trycompactmap(_:).md)
- [removeDuplicates()](combine/publisher/removeduplicates().md)
- [removeDuplicates(by:)](combine/publisher/removeduplicates(by:).md)
- [tryRemoveDuplicates(by:)](combine/publisher/tryremoveduplicates(by:).md)
- [replaceEmpty(with:)](combine/publisher/replaceempty(with:).md)
- [replaceError(with:)](combine/publisher/replaceerror(with:).md)

### Reducing elements

- [collect()](combine/publisher/collect().md)
- [collect(_:)](combine/publisher/collect(_:).md)
- [collect(_:options:)](combine/publisher/collect(_:options:).md)
- [Publishers.TimeGroupingStrategy](combine/publishers/timegroupingstrategy.md)
- [ignoreOutput()](combine/publisher/ignoreoutput().md)
- [reduce(_:_:)](combine/publisher/reduce(_:_:).md)
- [tryReduce(_:_:)](combine/publisher/tryreduce(_:_:).md)

### Applying mathematical operations on elements

- [count()](combine/publisher/count().md)
- [max()](combine/publisher/max().md)
- [max(by:)](combine/publisher/max(by:).md)
- [tryMax(by:)](combine/publisher/trymax(by:).md)
- [min()](combine/publisher/min().md)
- [min(by:)](combine/publisher/min(by:).md)
- [tryMin(by:)](combine/publisher/trymin(by:).md)

### Applying matching criteria to elements

- [contains(_:)](combine/publisher/contains(_:).md)
- [contains(where:)](combine/publisher/contains(where:).md)
- [tryContains(where:)](combine/publisher/trycontains(where:).md)
- [allSatisfy(_:)](combine/publisher/allsatisfy(_:).md)
- [tryAllSatisfy(_:)](combine/publisher/tryallsatisfy(_:).md)

### Applying sequence operations to elements

- [drop(untilOutputFrom:)](combine/publisher/drop(untiloutputfrom:).md)
- [dropFirst(_:)](combine/publisher/dropfirst(_:).md)
- [drop(while:)](combine/publisher/drop(while:).md)
- [tryDrop(while:)](combine/publisher/trydrop(while:).md)
- [append(_:)](combine/publisher/append(_:)-1qb8d.md)
- [append(_:)](combine/publisher/append(_:)-69sdn.md)
- [append(_:)](combine/publisher/append(_:)-5yh02.md)
- [prepend(_:)](combine/publisher/prepend(_:)-7wk5l.md)
- [prepend(_:)](combine/publisher/prepend(_:)-v9sb.md)
- [prepend(_:)](combine/publisher/prepend(_:)-5dj9c.md)
- [prefix(_:)](combine/publisher/prefix(_:).md)
- [prefix(while:)](combine/publisher/prefix(while:).md)
- [tryPrefix(while:)](combine/publisher/tryprefix(while:).md)
- [prefix(untilOutputFrom:)](combine/publisher/prefix(untiloutputfrom:).md)

### Selecting specific elements

- [first()](combine/publisher/first().md)
- [first(where:)](combine/publisher/first(where:).md)
- [tryFirst(where:)](combine/publisher/tryfirst(where:).md)
- [last()](combine/publisher/last().md)
- [last(where:)](combine/publisher/last(where:).md)
- [tryLast(where:)](combine/publisher/trylast(where:).md)
- [output(at:)](combine/publisher/output(at:).md)
- [output(in:)](combine/publisher/output(in:).md)

### Collecting and republishing the latest elements from multiple publishers

- [combineLatest(_:_:)](combine/publisher/combinelatest(_:_:)-1n30g.md)
- [combineLatest(_:)](combine/publisher/combinelatest(_:).md)
- [combineLatest(_:_:_:)](combine/publisher/combinelatest(_:_:_:)-6ekpz.md)
- [combineLatest(_:_:)](combine/publisher/combinelatest(_:_:)-5crqg.md)
- [combineLatest(_:_:_:_:)](combine/publisher/combinelatest(_:_:_:_:).md)
- [combineLatest(_:_:_:)](combine/publisher/combinelatest(_:_:_:)-48buc.md)

### Republishing elements from multiple publishers as an interleaved stream

- [merge(with:)](combine/publisher/merge(with:)-7fk3a.md)
- [merge(with:)](combine/publisher/merge(with:)-7qt71.md)
- [merge(with:_:)](combine/publisher/merge(with:_:).md)
- [merge(with:_:_:)](combine/publisher/merge(with:_:_:).md)
- [merge(with:_:_:_:)](combine/publisher/merge(with:_:_:_:).md)
- [merge(with:_:_:_:_:)](combine/publisher/merge(with:_:_:_:_:).md)
- [merge(with:_:_:_:_:_:)](combine/publisher/merge(with:_:_:_:_:_:).md)
- [merge(with:_:_:_:_:_:_:)](combine/publisher/merge(with:_:_:_:_:_:_:).md)

### Collecting and republishing the oldest unconsumed elements from multiple publishers

- [zip(_:)](combine/publisher/zip(_:).md)
- [zip(_:_:)](combine/publisher/zip(_:_:)-4xn21.md)
- [zip(_:_:)](combine/publisher/zip(_:_:)-8d7k7.md)
- [zip(_:_:_:)](combine/publisher/zip(_:_:_:)-9yqi1.md)
- [zip(_:_:_:)](combine/publisher/zip(_:_:_:)-16rcy.md)
- [zip(_:_:_:_:)](combine/publisher/zip(_:_:_:_:).md)

### Republishing elements by subscribing to new publishers

- [flatMap(maxPublishers:_:)](combine/publisher/flatmap(maxpublishers:_:)-3k7z5.md)
- [flatMap(maxPublishers:_:)](combine/publisher/flatmap(maxpublishers:_:)-qxf.md)
- [flatMap(maxPublishers:_:)](combine/publisher/flatmap(maxpublishers:_:)-hyb0.md)
- [flatMap(maxPublishers:_:)](combine/publisher/flatmap(maxpublishers:_:)-4of8w.md)
- [switchToLatest()](combine/publisher/switchtolatest()-453ht.md)
- [switchToLatest()](combine/publisher/switchtolatest()-1c51y.md)
- [switchToLatest()](combine/publisher/switchtolatest()-20v3t.md)
- [switchToLatest()](combine/publisher/switchtolatest()-9eb3r.md)

### Handling errors

- [assertNoFailure(_:file:line:)](combine/publisher/assertnofailure(_:file:line:).md)
- [catch(_:)](combine/publisher/catch(_:).md)
- [tryCatch(_:)](combine/publisher/trycatch(_:).md)
- [retry(_:)](combine/publisher/retry(_:).md)

### Controlling timing

- [measureInterval(using:options:)](combine/publisher/measureinterval(using:options:).md)
- [debounce(for:scheduler:options:)](combine/publisher/debounce(for:scheduler:options:).md)
- [delay(for:tolerance:scheduler:options:)](combine/publisher/delay(for:tolerance:scheduler:options:).md)
- [throttle(for:scheduler:latest:)](combine/publisher/throttle(for:scheduler:latest:).md)
- [timeout(_:scheduler:options:customError:)](combine/publisher/timeout(_:scheduler:options:customerror:).md)

### Encoding and decoding

- [encode(encoder:)](combine/publisher/encode(encoder:).md)
- [decode(type:decoder:)](combine/publisher/decode(type:decoder:).md)

### Identifying properties with key paths

- [map(_:)](combine/publisher/map(_:)-6sm0a.md)
- [map(_:_:)](combine/publisher/map(_:_:).md)
- [map(_:_:_:)](combine/publisher/map(_:_:_:).md)

### Working with multiple subscribers

- [multicast(_:)](combine/publisher/multicast(_:).md)
- [multicast(subject:)](combine/publisher/multicast(subject:).md)
- [share()](combine/publisher/share().md)

### Buffering elements

- [buffer(size:prefetch:whenFull:)](combine/publisher/buffer(size:prefetch:whenfull:).md)
- [Publishers.PrefetchStrategy](combine/publishers/prefetchstrategy.md)
- [Publishers.BufferingStrategy](combine/publishers/bufferingstrategy.md)

### Performing type erasure

- [eraseToAnyPublisher()](combine/publisher/erasetoanypublisher().md)

### Specifying schedulers

- [subscribe(on:options:)](combine/publisher/subscribe(on:options:).md)
- [receive(on:options:)](combine/publisher/receive(on:options:).md)

### Adding explicit connectability

- [makeConnectable()](combine/publisher/makeconnectable().md)

### 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)
- [sink(receiveValue:)](combine/publisher/sink(receivevalue:).md)

### Accessing elements asynchronously

- [values](combine/publisher/values-1dm9r.md)
- [values](combine/publisher/values-v7nz.md)

### Debugging

- [breakpoint(receiveSubscription:receiveOutput:receiveCompletion:)](combine/publisher/breakpoint(receivesubscription:receiveoutput:receivecompletion:).md)
- [breakpointOnError()](combine/publisher/breakpointonerror().md)
- [handleEvents(receiveSubscription:receiveOutput:receiveCompletion:receiveCancel:receiveRequest:)](combine/publisher/handleevents(receivesubscription:receiveoutput:receivecompletion:receivecancel:receiverequest:).md)
- [print(_:to:)](combine/publisher/print(_:to:).md)

## Relationships

### Inherited By

- [ConnectablePublisher](combine/connectablepublisher.md)
- [Subject](combine/subject.md)

### Conforming Types

- [AnyPublisher](combine/anypublisher.md)
- [CurrentValueSubject](combine/currentvaluesubject.md)
- [Deferred](combine/deferred.md)
- [Empty](combine/empty.md)
- [Fail](combine/fail.md)
- [Future](combine/future.md)
- [Just](combine/just.md)
- [ObservableObjectPublisher](combine/observableobjectpublisher.md)
- [PassthroughSubject](combine/passthroughsubject.md)
- [Published.Publisher](combine/published/publisher.md)
- [Publishers.AllSatisfy](combine/publishers/allsatisfy.md)
- [Publishers.AssertNoFailure](combine/publishers/assertnofailure.md)
- [Publishers.Autoconnect](combine/publishers/autoconnect.md)
- [Publishers.Breakpoint](combine/publishers/breakpoint.md)
- [Publishers.Buffer](combine/publishers/buffer.md)
- [Publishers.Catch](combine/publishers/catch.md)
- [Publishers.Collect](combine/publishers/collect.md)
- [Publishers.CollectByCount](combine/publishers/collectbycount.md)
- [Publishers.CollectByTime](combine/publishers/collectbytime.md)
- [Publishers.CombineLatest](combine/publishers/combinelatest.md)
- [Publishers.CombineLatest3](combine/publishers/combinelatest3.md)
- [Publishers.CombineLatest4](combine/publishers/combinelatest4.md)
- [Publishers.CompactMap](combine/publishers/compactmap.md)
- [Publishers.Comparison](combine/publishers/comparison.md)
- [Publishers.Concatenate](combine/publishers/concatenate.md)
- [Publishers.Contains](combine/publishers/contains.md)
- [Publishers.ContainsWhere](combine/publishers/containswhere.md)
- [Publishers.Count](combine/publishers/count.md)
- [Publishers.Debounce](combine/publishers/debounce.md)
- [Publishers.Decode](combine/publishers/decode.md)
- [Publishers.Delay](combine/publishers/delay.md)
- [Publishers.Drop](combine/publishers/drop.md)
- [Publishers.DropUntilOutput](combine/publishers/dropuntiloutput.md)
- [Publishers.DropWhile](combine/publishers/dropwhile.md)
- [Publishers.Encode](combine/publishers/encode.md)
- [Publishers.Filter](combine/publishers/filter.md)
- [Publishers.First](combine/publishers/first.md)
- [Publishers.FirstWhere](combine/publishers/firstwhere.md)
- [Publishers.FlatMap](combine/publishers/flatmap.md)
- [Publishers.HandleEvents](combine/publishers/handleevents.md)
- [Publishers.IgnoreOutput](combine/publishers/ignoreoutput.md)
- [Publishers.Last](combine/publishers/last.md)
- [Publishers.LastWhere](combine/publishers/lastwhere.md)
- [Publishers.MakeConnectable](combine/publishers/makeconnectable.md)
- [Publishers.Map](combine/publishers/map.md)
- [Publishers.MapError](combine/publishers/maperror.md)
- [Publishers.MapKeyPath](combine/publishers/mapkeypath.md)
- [Publishers.MapKeyPath2](combine/publishers/mapkeypath2.md)
- [Publishers.MapKeyPath3](combine/publishers/mapkeypath3.md)
- [Publishers.MeasureInterval](combine/publishers/measureinterval.md)
- [Publishers.Merge](combine/publishers/merge.md)
- [Publishers.Merge3](combine/publishers/merge3.md)
- [Publishers.Merge4](combine/publishers/merge4.md)
- [Publishers.Merge5](combine/publishers/merge5.md)
- [Publishers.Merge6](combine/publishers/merge6.md)
- [Publishers.Merge7](combine/publishers/merge7.md)
- [Publishers.Merge8](combine/publishers/merge8.md)
- [Publishers.MergeMany](combine/publishers/mergemany.md)
- [Publishers.Multicast](combine/publishers/multicast.md)
- [Publishers.Output](combine/publishers/output.md)
- [Publishers.PrefixUntilOutput](combine/publishers/prefixuntiloutput.md)
- [Publishers.PrefixWhile](combine/publishers/prefixwhile.md)
- [Publishers.Print](combine/publishers/print.md)
- [Publishers.ReceiveOn](combine/publishers/receiveon.md)
- [Publishers.Reduce](combine/publishers/reduce.md)
- [Publishers.RemoveDuplicates](combine/publishers/removeduplicates.md)
- [Publishers.ReplaceEmpty](combine/publishers/replaceempty.md)
- [Publishers.ReplaceError](combine/publishers/replaceerror.md)
- [Publishers.Retry](combine/publishers/retry.md)
- [Publishers.Scan](combine/publishers/scan.md)
- [Publishers.Sequence](combine/publishers/sequence.md)
- [Publishers.SetFailureType](combine/publishers/setfailuretype.md)
- [Publishers.Share](combine/publishers/share.md)
- [Publishers.SubscribeOn](combine/publishers/subscribeon.md)
- [Publishers.SwitchToLatest](combine/publishers/switchtolatest.md)
- [Publishers.Throttle](combine/publishers/throttle.md)
- [Publishers.Timeout](combine/publishers/timeout.md)
- [Publishers.TryAllSatisfy](combine/publishers/tryallsatisfy.md)
- [Publishers.TryCatch](combine/publishers/trycatch.md)
- [Publishers.TryCompactMap](combine/publishers/trycompactmap.md)
- [Publishers.TryComparison](combine/publishers/trycomparison.md)
- [Publishers.TryContainsWhere](combine/publishers/trycontainswhere.md)
- [Publishers.TryDropWhile](combine/publishers/trydropwhile.md)
- [Publishers.TryFilter](combine/publishers/tryfilter.md)
- [Publishers.TryFirstWhere](combine/publishers/tryfirstwhere.md)
- [Publishers.TryLastWhere](combine/publishers/trylastwhere.md)
- [Publishers.TryMap](combine/publishers/trymap.md)
- [Publishers.TryPrefixWhile](combine/publishers/tryprefixwhile.md)
- [Publishers.TryReduce](combine/publishers/tryreduce.md)
- [Publishers.TryRemoveDuplicates](combine/publishers/tryremoveduplicates.md)
- [Publishers.TryScan](combine/publishers/tryscan.md)
- [Publishers.Zip](combine/publishers/zip.md)
- [Publishers.Zip3](combine/publishers/zip3.md)
- [Publishers.Zip4](combine/publishers/zip4.md)
- [Record](combine/record.md)

## See Also

### Publishers

- [Publishers](combine/publishers.md)
- [AnyPublisher](combine/anypublisher.md)
- [Published](combine/published.md)
- [Cancellable](combine/cancellable.md)
- [AnyCancellable](combine/anycancellable.md)
