Here’s a version for Swift 5 that uses the Unicode scalar properties API to bail out if the first letter is already uppercase, or doesn’t have a notion of case:
extension String {
func firstLetterUppercased() -> String {
guard let first = first, first.isLowercase else { return self }
return String(first).uppercased() + dropFirst()
}
}