I was playing with CharacterSet, and I came up with:

let vowels = CharacterSet(charactersIn: "AEIOU")

let char: Character = "E"

vowels.contains(char)


That last line doesn't compile: I get "*cannot convert value of type
'Character' to expected argument type 'UnicodeScalar'*"

The problem is, I could not find a simple way to convert from a character
to a unicodeScalar. The best I found is the very ugly:

vowels.contains(String(char).unicodeScalars[String(char).unicodeScalars.
startIndex])

Did I miss anything? Does it have to be that horrific?

If so, I find using Set much better:

let vowelsSet: Set<Character> = Set("AEIOU".characters)

vowelsSet.contains(char)

I must have missed something. Any suggestion welcome

Jean-Denis
_______________________________________________
swift-users mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-users

Reply via email to