Skip to content

Instantly share code, notes, and snippets.

@sdulaney
Created September 24, 2018 23:57
Show Gist options
  • Select an option

  • Save sdulaney/569888a8a01f47251e0c47f80e0a4040 to your computer and use it in GitHub Desktop.

Select an option

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.
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