import Foundation
func isTitleCase(_ s: String) -> Bool {
for word in s.split(separator: " ") {
guard let first = word.first, first.isUppercase else {
return false
}
if word.dropFirst().contains(where: { !$0.isLowercase }) {
return false
}
}
return true
}
print(isTitleCase("Hello World")) // true
print(isTitleCase("Hello world")) // false
/*
run:
true
false
*/