How do I get the string before a certain character in swift? The code below is how I did it in Objective C, but can\'t seem to perform the same task in Swift. Any tips or su
You could use the method prefix(upTo:) in Swift 4 or above
var string = "hello Swift" if let index = string.firstIndex(of: " ") { let firstPart = string.prefix(upTo: index) print(firstPart) // print hello }