[swift-evolution] Better Swift interface for NSDecimal

Florian Reinhart florian at bottledsoftware.de
Fri Feb 26 09:41:11 CST 2016


Using NSDecimal from Swift isn’t fun. There are UnsafePointer<NSDecimal> all over the place.

It would be nice to have a Swift-like interface to work with NSDecimal. This can easily be achieved using an extension on NSDecimal. Here is something I quickly hacked together in a playground: https://gist.github.com/florianreinhart/99bb3a079075eaf640f1

The extension exposes all NSDecimal functions as mutating instance methods on NSDecimal. The instance methods throw if there is any error provided from the underlying NSDecimal function. I have also added operators, but I am not sure if this is a good idea.

What do you think about this?

How is the process of integrating something like this into Swift (since this is an API addition to Foundation)?

—Florian


More information about the swift-evolution mailing list