[swift-users] Replacement for NSNumber?

Maury Markowitz maury.markowitz at gmail.com
Mon Apr 11 10:04:18 CDT 2016


I have a primary data structure that is currently defined such:

var data: [String: NSNumber]

This is the only place in my app where I use a Foundation type *as* a Foundation type (as opposed to a bridge), and I would strongly prefer this to be purely Swift types.

I used NSNumber because the original data is variant, a mix of Int and Double - in some instances the first two entries in the dict are Ints, while in others it's the first four, and others are a mix based on other data points (it's very annoying). I could use two dictionaries, but this would *greatly* confuse code further into the program.

I know I could use Double and then floor the ints. But I'm wondering if I'm missing some more natural solution? I don't believe there is a common base type for Int and Double, but perhaps there is another way to solve this?


More information about the swift-users mailing list