Protocol

StringProtocol

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

Declaration

protocol StringProtocol 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.

Topics

Initializers

init(cString: UnsafePointer<CChar>)

Creates a string from the null-terminated, UTF-8 encoded sequence of bytes at the given pointer.

Required.

init<C, Encoding>(decoding: C, as: Encoding.Type)

Creates a string from the given Unicode code units in the specified encoding.

Required.

init<Encoding>(decodingCString: UnsafePointer<Encoding.CodeUnit>, as: Encoding.Type)

Creates a string from the null-terminated sequence of bytes at the given pointer.

Required.

Instance Methods

func hasPrefix(String) -> Bool

Required. Default implementation provided.

func hasSuffix(String) -> Bool

Required. Default implementation provided.

func withCString<Result>((UnsafePointer<CChar>) -> Result) -> Result

Calls the given closure with a pointer to the contents of the string, represented as a null-terminated sequence of UTF-8 code units.

Required.

func withCString<Result, Encoding>(encodedAs: Encoding.Type, (UnsafePointer<Encoding.CodeUnit>) -> Result) -> Result

Calls the given closure with a pointer to the contents of the string, represented as a null-terminated sequence of code units.

Required.

Operator Functions

static func == <RHS>(Self, RHS) -> Bool

Returns a Boolean value indicating whether two values are equal.

See Also

Related String Types

struct Substring

A slice of a string.

struct String.Index

A position of a character or code unit in a string.

struct String.UnicodeScalarView

A view of a string’s contents as a collection of Unicode scalar values.

struct String.UTF16View

A view of a string’s contents as a collection of UTF-16 code units.

struct String.UTF8View

A view of a string’s contents as a collection of UTF-8 code units.

struct String.Iterator

A type that provides the collection’s iteration interface and encapsulates its iteration state.