[swift-users] Replacement for NSNumber?

Joe Groff jgroff at apple.com
Mon Apr 11 11:46:35 CDT 2016


> On Apr 11, 2016, at 8:58 AM, Jens Alfke via swift-users <swift-users at swift.org> wrote:
> 
> Or just create an enum with an Int and a Double field. I believe this will be more efficient since the values can be stored inline, whereas indirecting through a protocol will force it to be boxed into a heap object (right?)

I would recommend an enum as well if Int and Double are literally the only two types you need to care about; it'll definitely be more efficient. However, a protocol type does have enough inline space to fit both Int and Double without spilling into a heap allocation.

-Joe


More information about the swift-users mailing list