<!--
{
  "availability" : [
    "iOS: 12.2.0 -",
    "iPadOS: 12.2.0 -",
    "macCatalyst: 12.2.0 -",
    "macOS: 10.14.4 -",
    "tvOS: 12.2.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 5.2.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/MutableRawSpan",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:s14MutableRawSpanV"
  },
  "title" : "MutableRawSpan"
}
-->

# MutableRawSpan

`MutableRawSpan` represents a contiguous region of memory
which contains initialized bytes.

```
@frozen struct MutableRawSpan
```

## Topics

### Initializers

[`init()`](/documentation/Swift/MutableRawSpan/init())

Create an empty span.

[`init<Element>(elements: consuming MutableSpan<Element>)`](/documentation/Swift/MutableRawSpan/init(elements:))

Convert a typed span to a raw span.

[`init<Element>(mutating: inout MutableSpan<Element>)`](/documentation/Swift/MutableRawSpan/init(mutating:))

Mutate the elements of a typed span as bytes.

[`init<Element>(unsafeElements: consuming MutableSpan<Element>)`](/documentation/Swift/MutableRawSpan/init(unsafeElements:))

Unsafely convert a typed span to a raw span.

### Instance Properties

[`var byteCount: Int`](/documentation/Swift/MutableRawSpan/byteCount)

The number of bytes in the span.

[`var byteOffsets: Range<Int>`](/documentation/Swift/MutableRawSpan/byteOffsets)

The valid byte offsets for accessing this span, in ascending order.

[`var bytes: RawSpan`](/documentation/Swift/MutableRawSpan/bytes)

Borrow the underlying initialized memory for read-only access.

[`var isEmpty: Bool`](/documentation/Swift/MutableRawSpan/isEmpty)

A Boolean value indicating whether the span is empty.

### Instance Methods

[`func extracting(Range<Int>) -> MutableRawSpan`](/documentation/Swift/MutableRawSpan/extracting(_:)-18k75)

Constructs a new span over the bytes within the supplied range of
positions within this span.

[`func extracting(some RangeExpression<Int>) -> MutableRawSpan`](/documentation/Swift/MutableRawSpan/extracting(_:)-6fpo6)

Constructs a new span over the bytes within the supplied range of
positions within this span.

[`func extracting(UnboundedRange) -> MutableRawSpan`](/documentation/Swift/MutableRawSpan/extracting(_:)-7d5f1)

Constructs a new span over all the bytes of this span.

[`func extracting(droppingFirst: Int) -> MutableRawSpan`](/documentation/Swift/MutableRawSpan/extracting(droppingFirst:))

Returns a span over all but the given number of initial bytes.

[`func extracting(droppingLast: Int) -> MutableRawSpan`](/documentation/Swift/MutableRawSpan/extracting(droppingLast:))

Returns a span over all but the given number of trailing bytes.

[`func extracting(first: Int) -> MutableRawSpan`](/documentation/Swift/MutableRawSpan/extracting(first:))

Returns a span containing the initial bytes of this span,
up to the specified maximum length.

[`func extracting(last: Int) -> MutableRawSpan`](/documentation/Swift/MutableRawSpan/extracting(last:))

Returns a span containing the trailing bytes of the span,
up to the given maximum length.

[`func extracting(unchecked: ClosedRange<Int>) -> MutableRawSpan`](/documentation/Swift/MutableRawSpan/extracting(unchecked:)-4b7xa)

Constructs a new span over the bytes within the supplied range of
positions within this span.

[`func extracting(unchecked: Range<Int>) -> MutableRawSpan`](/documentation/Swift/MutableRawSpan/extracting(unchecked:)-7oy38)

Constructs a new span over the bytes within the supplied range of
positions within this span.

[`func load<T>(fromByteOffset: Int, as: T.Type) -> T`](/documentation/Swift/MutableRawSpan/load(fromByteOffset:as:))

Returns a value constructed from the raw memory at the specified offset.

[`func load<T>(fromByteOffset: Int, as: T.Type, ByteOrder) -> T`](/documentation/Swift/MutableRawSpan/load(fromByteOffset:as:_:))

Returns a value constructed from the raw memory at the specified offset.

[`func storeBytes<T>(of: T, toByteOffset: Int, as: T.Type)`](/documentation/Swift/MutableRawSpan/storeBytes(of:toByteOffset:as:)-1afju)

Stores the given value’s bytes to the specified offset into
the span’s memory.

[`func storeBytes<T>(of: T, toByteOffset: Int, as: T.Type)`](/documentation/Swift/MutableRawSpan/storeBytes(of:toByteOffset:as:)-37pwo)

Stores the given value’s bytes into the span’s raw memory at the
specified byte offset.

[`func storeBytes<T>(of: T, toByteOffset: Int, as: T.Type, ByteOrder)`](/documentation/Swift/MutableRawSpan/storeBytes(of:toByteOffset:as:_:))

Stores the given value’s bytes to the specified offset into
the span’s memory.

[`func storeBytes<T>(of: T, toUncheckedByteOffset: Int, as: T.Type)`](/documentation/Swift/MutableRawSpan/storeBytes(of:toUncheckedByteOffset:as:))

Stores the given value’s bytes into the span’s raw memory at the
specified byte offset.

[`func storeBytes<T>(repeating: T, count: Int, as: T.Type)`](/documentation/Swift/MutableRawSpan/storeBytes(repeating:count:as:)-6822y)

Stores the given value’s bytes repeatedly into this span’s memory.

[`func storeBytes<T>(repeating: T, count: Int, as: T.Type)`](/documentation/Swift/MutableRawSpan/storeBytes(repeating:count:as:)-7cd7p)

Stores the given value’s bytes repeatedly into this span’s memory.

[`func storeBytes<T>(repeating: T, count: Int, as: T.Type, ByteOrder)`](/documentation/Swift/MutableRawSpan/storeBytes(repeating:count:as:_:))

Stores the given value’s bytes repeatedly into this span’s memory.

[`func unsafeLoad<T>(fromByteOffset: Int, as: T.Type) -> T`](/documentation/Swift/MutableRawSpan/unsafeLoad(fromByteOffset:as:))

Returns a new instance of the given type, constructed from the raw memory
at the specified offset.

[`func unsafeLoad<T>(fromUncheckedByteOffset: Int, as: T.Type) -> T`](/documentation/Swift/MutableRawSpan/unsafeLoad(fromUncheckedByteOffset:as:))

Returns a new instance of the given type, constructed from the raw memory
at the specified offset.

[`func unsafeLoadUnaligned<T>(fromByteOffset: Int, as: T.Type) -> T`](/documentation/Swift/MutableRawSpan/unsafeLoadUnaligned(fromByteOffset:as:))

Returns a new instance of the given type, constructed from the raw memory
at the specified offset.

[`func unsafeLoadUnaligned<T>(fromUncheckedByteOffset: Int, as: T.Type) -> T`](/documentation/Swift/MutableRawSpan/unsafeLoadUnaligned(fromUncheckedByteOffset:as:))

Returns a new instance of the given type, constructed from the raw memory
at the specified offset.

[`func withUnsafeBytes<E, Result>((UnsafeRawBufferPointer) throws(E) -> Result) throws(E) -> Result`](/documentation/Swift/MutableRawSpan/withUnsafeBytes(_:))

Calls the given closure with a pointer to the underlying bytes of
the viewed contiguous storage.

[`func withUnsafeMutableBytes<E, Result>((UnsafeMutableRawBufferPointer) throws(E) -> Result) throws(E) -> Result`](/documentation/Swift/MutableRawSpan/withUnsafeMutableBytes(_:))

Calls the given closure with a mutable pointer to the underlying bytes
of the viewed contiguous storage.

### Subscripts

[`subscript(Int) -> UInt8`](/documentation/Swift/MutableRawSpan/subscript(_:))

Accesses the byte at the specified offset in the span.

[`subscript(unchecked _: Int) -> UInt8`](/documentation/Swift/MutableRawSpan/subscript(unchecked:))

Accesses the byte at the specified offset in the span.

### Default Implementations

[Iterable Implementations](/documentation/Swift/MutableRawSpan/Iterable-Implementations)

## Relationships

### Conforms To

[`ContiguousBytes`](/documentation/Foundation/ContiguousBytes)

[`Sendable`](/documentation/Swift/Sendable)

[`Iterable`](/documentation/Swift/Iterable)

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

---

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)