<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.10.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/Slice/update(fromContentsOf:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:s5SliceV6update14fromContentsOfSiqd_0__tSryqd__GRsz7ElementQyd_0_Rsd__SlRd_0_r0_lF"
  },
  "title" : "update(fromContentsOf:)"
}
-->

# update(fromContentsOf:)

Updates the buffer slice’s initialized memory with
every element of the source.

```
func update<Element>(fromContentsOf source: some Collection) -> Slice<Base>.Index where Base == UnsafeMutableBufferPointer<Element>
```

## Parameters

`source`

A collection of elements to be used to update
the buffer’s contents.

## Return Value

An index one past the index of the last element updated.

## Discussion

Prior to calling the `update(fromContentsOf:)` method on a buffer
slice, the first `source.count` elements of the referenced memory must be
initialized, or the `Element` type must be a trivial type.
The buffer slice must reference enough initialized memory to accommodate
`source.count` elements.

The returned index is one past the index of the last element updated. If
`source` contains no elements, the returned index is the buffer slice’s
`startIndex`. If `source` contains as many elements as the buffer slice
can hold, the returned index is the buffer slice’s `endIndex`.

> Note: The memory regions referenced by `source` and this buffer slice
> may overlap.

> Precondition: `self.count` >= `source.count`

---

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)