---
title: Span
framework: swift
role: symbol
role_heading: Structure
path: swift/span
---

# Span

Span<Element> represents a contiguous region of memory which contains initialized instances of Element.

## Declaration

```swift
@frozen struct Span<Element> where Element : ~Copyable
```

## Overview

Overview A Span instance is a non-owning, non-escaping view into memory. When a Span is created, it inherits the lifetime of the container owning the contiguous memory, ensuring temporal safety and avoiding use-after-free errors. Operations on Span are bounds-checked, ensuring spatial safety and avoiding buffer overflow errors.

## Topics

### Initializers

- [init()](swift/span/init().md)

### Instance Properties

- [bytes](swift/span/bytes.md)
- [count](swift/span/count.md)
- [indices](swift/span/indices.md)
- [isEmpty](swift/span/isempty.md)

### Instance Methods

- [extracting(_:)](swift/span/extracting(_:)-1c6e6.md)
- [extracting(_:)](swift/span/extracting(_:)-48neh.md)
- [extracting(_:)](swift/span/extracting(_:)-57peb.md)
- [extracting(droppingFirst:)](swift/span/extracting(droppingfirst:).md)
- [extracting(droppingLast:)](swift/span/extracting(droppinglast:).md)
- [extracting(first:)](swift/span/extracting(first:).md)
- [extracting(last:)](swift/span/extracting(last:).md)
- [extracting(unchecked:)](swift/span/extracting(unchecked:)-46y0h.md)
- [extracting(unchecked:)](swift/span/extracting(unchecked:)-8hfj1.md)
- [indices(of:)](swift/span/indices(of:).md)
- [isIdentical(to:)](swift/span/isidentical(to:).md)
- [isTriviallyIdentical(to:)](swift/span/istriviallyidentical(to:).md)
- [withBytes(_:)](swift/span/withbytes(_:).md)
- [withUnsafeBufferPointer(_:)](swift/span/withunsafebufferpointer(_:).md)
- [withUnsafeBytes(_:)](swift/span/withunsafebytes(_:).md)

### Subscripts

- [subscript(_:)](swift/span/subscript(_:)-2g4jz.md)
- [subscript(_:)](swift/span/subscript(_:)-3r1qm.md)
- [subscript(unchecked:)](swift/span/subscript(unchecked:)-2no6f.md)
- [subscript(unchecked:)](swift/span/subscript(unchecked:)-6gur1.md)

### Type Aliases

- [Span.Index](swift/span/index.md)

### Default Implementations

- [BorrowingSequence Implementations](swift/span/borrowingsequence-implementations.md)

## Relationships

### Conforms To

- [BitwiseCopyable](swift/bitwisecopyable.md)
- [BorrowingSequence](swift/borrowingsequence.md)
- [ContiguousBytes](foundation/contiguousbytes.md)
- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)

## See Also

### Safe Memory Access

- [RawSpan](swift/rawspan.md)
- [OutputSpan](swift/outputspan.md)
- [OutputRawSpan](swift/outputrawspan.md)
- [UTF8Span](swift/utf8span.md)
- [MutableSpan](swift/mutablespan.md)
- [MutableRawSpan](swift/mutablerawspan.md)
