Uploaded image for project: 'Swift'
  1. Swift
  2. SR-2303

ExpressibleByStringInterpolation: ability to restrict types used in string interpolation

    XMLWordPrintable

    Details

      Description

      It's desirable for types conforming to ExpressibleByStringInterpolation to be able to restrict the kinds of values that can be used in string interpolation.

      The following example is a simplified version of Brent Royal-Gordon's example from the swift-evolution thread:

      // We want LocalizedString to be formed from a string interpolation;
      // only LocalizedStringConvertible values should be allowed as interpolated values.
      
      protocol LocalizedStringConvertible { ... }
      struct LocalizedString { ... }
      
      extension LocalizedString: ExpressibleByStringInterpolation {
          init(stringInterpolation segments: LocalizedString...) { }
          init(stringInterpolationSegment value: LocalizedStringConvertible) { ... }
          // no init<T>(stringInterpolationSegment:) is provided; only LocalizedStringConvertible values are valid
      }
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                brentdax Brent Royal-Gordon
                Reporter:
                jtbandes Jacob Bandes-Storch
              • Votes:
                1 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated: