ExpressibleByStringLiteral

protocol ExpressibleByStringLiteral

A type that can be initialized with a string literal.

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.

Inheritance ExpressibleByExtendedGraphemeClusterLiteral, ExpressibleByUnicodeScalarLiteral View Protocol Hierarchy →
Associated Types
StringLiteralType : _ExpressibleByBuiltinStringLiteral

A type that represents a string literal.

Valid types for StringLiteralType are String and StaticString.

ExtendedGraphemeClusterLiteralType : _ExpressibleByBuiltinExtendedGraphemeClusterLiteral

A type that represents an extended grapheme cluster literal.

Valid types for ExtendedGraphemeClusterLiteralType are Character, String, and StaticString.

UnicodeScalarLiteralType : _ExpressibleByBuiltinUnicodeScalarLiteral

A type that represents a Unicode scalar literal.

Valid types for UnicodeScalarLiteralType are Unicode.Scalar, Character, String, and StaticString.

Import import Swift

Initializers

init(stringLiteral:) Required

Creates an instance initialized to the given string value.

value: The value of the new instance.

Declaration

init(stringLiteral value: Self.StringLiteralType)
init(extendedGraphemeClusterLiteral:) Required

Creates an instance initialized to the given value.

value: The value of the new instance.

Declaration

init(extendedGraphemeClusterLiteral value: Self.ExtendedGraphemeClusterLiteralType)

Declared In

ExpressibleByExtendedGraphemeClusterLiteral
init(unicodeScalarLiteral:) Required

Creates an instance initialized to the given value.

value: The value of the new instance.

Declaration

init(unicodeScalarLiteral value: Self.UnicodeScalarLiteralType)

Declared In

ExpressibleByUnicodeScalarLiteral

Default Implementations

Where ExtendedGraphemeClusterLiteralType == StringLiteralType

init(extendedGraphemeClusterLiteral:)

Declaration

init(extendedGraphemeClusterLiteral value: Self.StringLiteralType)

Where ExtendedGraphemeClusterLiteralType == UnicodeScalarLiteralType

init(unicodeScalarLiteral:)

Creates an instance initialized to the given value.

value: The value of the new instance.

Declaration

init(unicodeScalarLiteral value: Self.ExtendedGraphemeClusterLiteralType)

Declared In

ExpressibleByExtendedGraphemeClusterLiteral