Created
September 24, 2018 23:57
-
-
Save sdulaney/569888a8a01f47251e0c47f80e0a4040 to your computer and use it in GitHub Desktop.
Example showing the Swift 4.2 method firstIndex, now working in Xcode 10.0.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let greeting = "Hello, world!" | |
| let index = greeting.firstIndex(of: ",") ?? greeting.endIndex | |
| let beginning = greeting[..<index] | |
| // beginning is "Hello" | |
| // Convert the result to a String for long-term storage. | |
| let newString = String(beginning) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment