Skip to main content
InterviewHubPRO
Section Overview
Q49

Question 49 of 50

Part 3: Runtime Internals, Swift 6 Safety & Systems Programming (25 - 35)

98%
Swift & Concurrency (50 Qs)•Part 3: Runtime Internals, Swift 6 Safety & Systems Programming (25 - 35)

Custom String Interpolation and `ExpressibleByLiteral` protocols.

senior LevelCode ExampleswiftRuntime Internals

In Simple Words:

  • ExpressibleByStringLiteral / ExpressibleByIntegerLiteral: Allows custom types to be initialized directly from literals (let id: UserID = 1042).
  • Custom String Interpolation: Extend String.StringInterpolation to create secure, type-safe formatters:
    swift
    extension String.StringInterpolation {
      mutating func appendInterpolation(privacy value: String) {
        appendLiteral("***" + value.suffix(4))
      }
    }
    print("SSN: (privacy: ssn)") // "SSN: ***1234"