Protocol

ExpressibleByStringLiteral

A type that can be initialized with a string literal.

Declaration

protocol ExpressibleByStringLiteral

Overview

The String and StaticString types conform to the ExpressibleByStringLiteral protocol. You can initialize a variable or constant of either of these types using a string literal of any length.

let picnicGuest = "Deserving porcupine"

Conforming to ExpressibleByStringLiteral

To add ExpressibleByStringLiteral conformance to your custom type, implement the required initializer.

Topics

Associated Types

associatedtype StringLiteralType

A type that represents a string literal.

Required.

Initializers

init(stringLiteral: Self.StringLiteralType)

Creates an instance initialized to the given string value.

Required.

See Also

String Literals

protocol ExpressibleByExtendedGraphemeClusterLiteral

A type that can be initialized with a string literal containing a single extended grapheme cluster.

protocol ExpressibleByUnicodeScalarLiteral

A type that can be initialized with a string literal containing a single Unicode scalar value.

protocol ExpressibleByStringInterpolation

A type that can be initialized by string interpolation with a string literal that includes expressions.

protocol StringInterpolationProtocol

Represents the contents of a string literal with interpolations while it’s being built up.

struct DefaultStringInterpolation

Represents a string literal with interpolations while it is being built up.