[swift-users] CharacterSet vs Set<Character>

Quinn "The Eskimo!" eskimo1 at apple.com
Mon Oct 3 02:43:55 CDT 2016

On 2 Oct 2016, at 19:02, Jean-Denis Muys via swift-users <swift-users at swift.org> wrote:

> The problem is, I could not find a simple way to convert from a character to a unicodeScalar. 

As is often the case with string examples, it would help if you posted more about your context.  With the details we have now your code could be written like this:

let vowels = CharacterSet(charactersIn: "AEIOU")
let char: UnicodeScalar = "E"

but I’m pretty sure that won’t help in your real app (-:  So, my questions:

* Do you plan to use a fixed character set?  Or is the character set itself built at runtime?

* Do you have specific knowledge of either of the inputs?  Like that they’re all ASCII?  Or normalised in a certain way?

* Specifically, where do the characters you’re trying to test (`char` in your example) come from?  Do they represent user input, in which case they can be arbitrary Unicode?  Or something more constrained

Share and Enjoy
Quinn "The Eskimo!"                    <http://www.apple.com/developer/>
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

More information about the swift-users mailing list