Alex Mitchell Alex Mitchell - 2 months ago 20
Swift Question

What is the replacement for isDigit() for characters in Swift?

As mentioned in this post, before Xcode 6 Beta 4, one could use

c.isDigit()
and
c.isAlpha()
to find if
c : Character
was a digit or alpha. The post mentions that this was removed as it was only effective for ASCII characters.

My question is, what's the replacement? Short of setting up a function with a switch statement for alphanumeric options, how can I test a character on its digit-ness?

Answer

The "problem" is that a Swift character does not directly correspond to a Unicode code point, but represents an "extended grapheme cluster" which can consist of multiple Unicode scalars. For example

let c : Character = "
Comments