How to use ICU in Swift?

How might / should one go about using the ICU library in Swift? It's imported (into Swift) by the Swift standard library but nominally only for the standard library's use (and apparently it's treated as private for App Store submission purposes, so unusable).

I found only one package that attempts this already, icu-swift, but it's been untouched for six years and relies on the aforementioned private version of ICU (or, statically linking in a second copy, which seems bad for scalability).

While this was true in older versions of Swift, the Swift standard library no longer uses ICU for multiple releases. Its only remaining user is Foundation, both swift-corelibs-foundation, and the new swift-foundation package that you linked to.

Using the new swift-foundation-icu package seems to be an appropriate way to get access to ICU functions, especially as it's versioned and exports a few ICU modules. Not sure though if it's guaranteed to be API or ABI stable, given that it's at 0.0.2 right now.

Important to note, if you use both swift-corelibs-foundation and swift-foundation-icu, you'll get two copies of ICU in your binary, in addition to the non-ICU Unicode tables already present in the stdlib.

If you don't use swift-corelibs-foundation, you'll get a single copy of ICU with swift-foundation-icu. Unicode tables will still be duplicated, which is currently unavoidable.

3 Likes