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

'Substring.SubSequence' (aka 'Substring') has no member 'trimmingCharacters' or 'hasSuffix'

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Medium
    • Resolution: Done
    • Component/s: Foundation
    • Labels:
      None
    • Environment:

      Linux w/ Swift 4

      Description

      I'm trying to do some string processing that looks something like this:

      import Foundation

      let lines = """
      BuildVersion: "123"
      ProductType: "SomeProduct1,2"
      HWModelStr: "TotallyNotAP"
      """

      for line in lines.split(separator: "\n", omittingEmptySubsequences: true) {
      var x: String
      if line.starts(with: "BuildVersion")

      { x = String(line.split(separator: "\"")[1]) }

      else if line.starts(with: "ProductType")

      { x = line.split(separator: "\"")[1] .trimmingCharacters(in: CharacterSet.letters.inverted) .lowercased() }

      else if line.starts(with: "HWModelStr") {
      let y = line.split(separator: "\"")[1]
      if y.hasSuffix("AP")

      { x = String(y.dropLast(2)) }

      else

      { x = String(y) }

      } else

      { x = "" }

      print
      }

      Which works in Darwin land,
      >>>
      123
      someproduct
      TotallyNot

      but on Linux I get errors like

      error: terminated(1): /usr/bin/swift-build-tool -f /swift-execution/.build/debug.yaml main
      ERROR at line 34, col 40: value of type 'Substring.SubSequence' (aka 'Substring') has no member 'trimmingCharacters'
      x = line.split(separator: "\"")[1]
      ~~~~~~~~~~~~~~~~~~~~~~~~~~^~
      ERROR at line 39, col 12: value of type 'Substring.SubSequence' (aka 'Substring') has no member 'hasSuffix'
      if y.hasSuffix("AP") {
      ^ ~~~~~~~~~

      I would expect these functions to work here.

        Attachments

          Activity

            People

            Assignee:
            Unassigned
            Reporter:
            p_thompson Paul Thompson
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: