cyril
cyril

Reputation: 3005

Why won't substrings work in Swift 4 anymore?

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

Upvotes: 1

Views: 749

Answers (1)

Magnas
Magnas

Reputation: 4063

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.

Upvotes: 4

Related Questions