Open ViewController.swift, and replace the implementation of makeHeadline(from:) with the following lines of code:
func makeHeadline(from string: String) -> String { let words = string.components(separatedBy: " ") var headline = "" for var word in words { let firstCharacter = word.remove(at: word.startIndex) headline += "\(String(firstCharacter).uppercased())\(word) " } headline.remove(at: headline.index(before: headline.endIndex)) return headline }
Let's go through this implementation step by step:
- Split the string into words.
- Iterate over the words, and remove the first character and change it to uppercase. Add the changed character to the beginning of the word. Add this word with a trailing space to the headline string. ...