---
title: utf8Span
framework: swift
role: symbol
role_heading: Instance Property
path: swift/substring/utf8span
---

# utf8Span

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

## Declaration

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

## Return Value

Return Value A UTF8Span over the code units of this substring.

## Discussion

Discussion note: In the case of bridged UTF-16 string instances (on Apple platforms) this property needs to transcode the code units every time it’s called. For example, if string has the bridged UTF-16 representation, the following code is accidentally quadratic because of this issue: for word in string.split(separator: " ") {     useSpan(word.span) } A workaround is to explicitly convert the string into its native UTF-8 representation: var nativeString = consume string nativeString.makeContiguousUTF8() for word in nativeString.split(separator: " ") {     useSpan(word.span) } This second option has linear time complexity, as expected. note: O(1) for native UTF-8 strings, O(n) for bridged UTF-16 strings.
