Protocol

ExpressibleByStringLiteral

A type that can be initialized with a string literal.

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.