Better Swift interface for NSDecimal

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: NSDecimal+Swift.swift · GitHub

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

Hi Florian,

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: NSDecimal+Swift.swift · GitHub

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)?

Right now we’re pretty wrapped up in the naming changes and other work, but it’s clear NSDecimal can use some attention in Swift. I’m hoping it is something we can spend some time on soon, but I don’t have any concrete plans for Swift 3.

- Tony

···

On Feb 26, 2016, at 7:41 AM, Florian Reinhart via swift-evolution <swift-evolution@swift.org> wrote:

—Florian
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution