<!--
{
  "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/Publisher/buffer(size:prefetch:whenFull:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Combine"
    ],
    "preciseIdentifier" : "s:7Combine9PublisherPAAE6buffer4size8prefetch8whenFullAA10PublishersO6BufferVy_xGSi_AI16PrefetchStrategyOAI09BufferingK0Oy_7FailureQzGtF"
  },
  "title" : "buffer(size:prefetch:whenFull:)"
}
-->

# buffer(size:prefetch:whenFull:)

Buffers elements received from an upstream publisher.

```
func buffer(size: Int, prefetch: Publishers.PrefetchStrategy, whenFull: Publishers.BufferingStrategy<Self.Failure>) -> Publishers.Buffer<Self>
```

## Parameters

`size`

The maximum number of elements to store.

`prefetch`

The strategy to initially populate the buffer.

`whenFull`

The action to take when the buffer becomes full.

## Return Value

A publisher that buffers elements received from an upstream publisher.

## Discussion

Use [`buffer(size:prefetch:whenFull:)`](/documentation/Combine/Publisher/buffer(size:prefetch:whenFull:)) to collect a specific number of elements from an upstream publisher before republishing them to the downstream subscriber according to the [`Publishers.BufferingStrategy`](/documentation/Combine/Publishers/BufferingStrategy) and [`Publishers.PrefetchStrategy`](/documentation/Combine/Publishers/PrefetchStrategy) strategy you specify.

If the publisher completes before reaching the `size` threshold, it buffers the elements and publishes them downstream prior to completion.

---

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)