Protocol

StringProtocol

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

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 withCString<Result>((UnsafePointer<CChar>) -> 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)

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

Required.

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.CharacterView

A view of a string’s contents as a collection of characters.

Deprecated
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.