I've seen other answers to this question, but I'm just trying to do it differently. Yet whatever I do I can't make my types match.
func ContainsOnlyAlphabets(_ word : String) -> Bool{
let letters = CharacterSet.letters // Set<Character>
let trimmed = word.trimmingCharacters(in: .whitespaces)
let characterViewArray = Array(trimmed.characters) // Array<characterView>
let characterArray = characterViewArray.map{Character($0)} // Error: Can't create Chars
let wordCharactersSet = Set(characterArray) // Set<Character>
let intersection = wordCharactersSet.intersection(letters)
return intersection.count == characterArray.count
}
I had to do all the Set,Char,String,Array conversions but still couldn't get it right :(.
cannot invoke initializer for type 'Character' with an argument list of type '((String.CharacterView._Element))'