Alex Mitchell Alex Mitchell - 1 month ago 4x
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

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?


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 = "