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

A type that can represent a string literal.

Valid types for StringLiteralType are String and StaticString.

  • ExtendedGraphemeClusterLiteralType

A type that can represent an extended grapheme cluster literal.

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

  • UnicodeScalarLiteralType

A type that can represent a Unicode scalar literal.

Valid types for UnicodeScalarLiteralType are UnicodeScalar, String, and StaticString.

2 inherited items hidden. (Show all)

Import
  • import Swift

Initializers

init(stringLiteral:) Required

Creates an instance initialized to the given string value.

Declaration

init(extendedGraphemeClusterLiteral:) Required

Creates an instance initialized to the given value.

Declaration

  • init(extendedGraphemeClusterLiteral value: Self.ExtendedGraphemeClusterLiteralType)

Declared In

ExpressibleByExtendedGraphemeClusterLiteral
init(unicodeScalarLiteral:) Required

Creates an instance initialized to the given value.

Declaration

  • init(unicodeScalarLiteral value: Self.UnicodeScalarLiteralType)

Declared In

ExpressibleByUnicodeScalarLiteral

2 inherited items hidden. (Show all)