[swift-users] Replacement for NSNumber?
slaunchaman at gmail.com
Mon Apr 11 10:06:13 CDT 2016
One possible solution is to create an empty Protocol that both Int and Double conform to, perhaps DataValue, and then create your data structure like this:
var data: [String: DataValue]
SlaunchaMan at gmail.com | @SlaunchaMan <https://twitter.com/SlaunchaMan> | jeffkelley.org <http://jeffkelley.org/>
> On Apr 11, 2016, at 11:04 AM, Maury Markowitz via swift-users <swift-users at swift.org> wrote:
> 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?
> swift-users mailing list
> swift-users at swift.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-users