<!--
{
  "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/StringProtocol",
  "metadataVersion" : "0.1.0",
  "role" : "Protocol",
  "symbol" : {
    "kind" : "Protocol",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:Sy"
  },
  "title" : "StringProtocol"
}
-->

# StringProtocol

A type that can represent a string as a collection of characters.

```
protocol StringProtocol : BidirectionalCollection, Comparable, ExpressibleByStringInterpolation, Hashable, LosslessStringConvertible, TextOutputStream, TextOutputStreamable where Self.Element == Character, Self.Index == String.Index, Self.StringInterpolation == DefaultStringInterpolation, Self.SubSequence : StringProtocol
```

## Overview

Do not declare new conformances to `StringProtocol`. Only the `String` and
`Substring` types in the standard library are valid conforming types.

## Relationships

### Inherits From

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

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

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

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

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

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

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

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

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

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

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

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

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

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

### Conforming Types

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

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

---

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)