1

one of the pods in my project won't compile and I can't figure out why. Truthfully, I've never had to deal with String.UnicodeScalarView so I have no idea what that is and the docs aren't being very helpful. They are still using string[subscript] in the Swift 4 documentation but Xcode is complaining about subscript being obsolete. Any ideas? enter image description here

cyril
  • 3,020
  • 6
  • 36
  • 61
  • Please show your code and full error message as text. – OOPer Aug 09 '17 at 01:17
  • Possible duplicate of [String, substring, Range, NSRange in Swift 4](https://stackoverflow.com/questions/45449186/string-substring-range-nsrange-in-swift-4) – l'L'l Aug 09 '17 at 01:58

1 Answers1

4

I came across the exact same error in exactly the same place (same Mapbox file). I believe the problem has to do with the new substring type being distinct from the String type which breaks the code at the line you indicate. I'm still trying to understand the new docs. Anyway I took a punt and tried the following, using String.UnicodescalarView (which I"ve not come across either)

encodedString = String.UnicodeScalarView(encodedString[encodedString.index(after: currentIndex)..<encodedString.endIndex])

Be aware that while this allows the code to compile and run, it involves unlocking a file in the pod (to allow editing) and so you should use with caution and make sure to update the pod as soon as Mapbox release an update. This isn't a long term fix at all.

Magnas
  • 3,832
  • 5
  • 33
  • 48
  • Thanks for this! I'll mark it as the right answer for now. At least the code compiles :p – cyril Aug 09 '17 at 17:41
  • 1
    In Swift 4, when you subscript a `String` with a range, it produce a `SubString` instead of `UnicodeScalarView` in Swift 3. I've always felt that strings in Swift are terribly designed and major releases don't do much to help. The `SubString` proposal is here: https://github.com/apple/swift-evolution/blob/master/proposals/0163-string-revision-1.md – Code Different Aug 11 '17 at 20:46
  • @Code Different - Completely agree and thanks for the link. – Magnas Aug 12 '17 at 11:28