ExpressibleByStringLiteral

protocol ExpressibleByStringLiteral

A type that can be initialized with a string literal.

Inheritance ExpressibleByExtendedGraphemeClusterLiteral
Conforming Types ExpressibleByStringInterpolation, StaticString, String, Substring
Associated Types
associatedtype StringLiteralType

Valid types for StringLiteralType are String and StaticString.

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.

Initializers

init init(stringLiteral:) Required

Creates an instance initialized to the given string value.

  • Parameter value: The value of the new instance.

Declaration

init(stringLiteral value: Self.StringLiteralType)