<!--
{
  "availability" : [
    "iOS: 26.0.0 -",
    "iPadOS: 26.0.0 -",
    "macCatalyst: 26.0.0 -",
    "macOS: 26.0.0 -",
    "tvOS: 26.0.0 -",
    "visionOS: 26.0.0 -",
    "watchOS: 26.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/Substring/utf8Span",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Property",
  "symbol" : {
    "kind" : "Instance Property",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:Ss8utf8Spans04UTF8B0Vvp"
  },
  "title" : "utf8Span"
}
-->

# utf8Span

A UTF-8 span over the code units that make up this substring.

```
var utf8Span: UTF8Span { get }
```

## Return Value

A `UTF8Span` over the code units of this `Substring`.

## Discussion> Note: On Apple platforms, this property must transcode the code
> units of bridged UTF-16 `String` instances on every access.
> 
> For example, if `string` has the bridged UTF-16 representation,

```swift
  for word in string.split(separator: " ") {
      useSpan(word.span)
  }
```

is accidentally quadratic because of this issue. A workaround is to
explicitly convert the string into its native UTF-8 representation:

```swift
  var nativeString = consume string
  nativeString.makeContiguousUTF8()
  for word in nativeString.split(separator: " ") {
      useSpan(word.span)
  }
```

This second option has linear time complexity, as expected.

> Complexity: O(1) for native UTF-8 strings, O(*n*) for bridged UTF-16
> strings.

---

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)