Re: Comparing results of @encode
Re: Comparing results of @encode
- Subject: Re: Comparing results of @encode
- From: "Michael Ash" <email@hidden>
- Date: Mon, 27 Oct 2008 00:47:25 -0400
On Sun, Oct 26, 2008 at 6:23 PM, Graham Cox <email@hidden> wrote:
>> Also note that NSNumber is smart enough to automatically convert its
>> internal representation to whatever you ask for. So for example if
>> 'double' encompasses every value you might need, then it's safe to
>> simply use [myNumber doubleValue] even if you created it as an int or
>> float value.
>
> Understood, though in fact that's a slight hindrance in my case. Given an
> arbitrary NSNumber, I need to know its type - int, bool or float at the very
> least. If it gets converted to some other representation internally, it
> means that I could find types "mutating" from float to double, say.
>
> Still, I have it working and it seems to be OK for now. I can live with
> float->double for example, though bool->int would be a problem. However it
> seems that doesn't occur.
As far as I know the conversion happens upon request, not upon
storage. In other words, the internal representation is of the type
you initially used to create the NSNumber. If you then request the
value through a method whose type doesn't match, it retrieves the
internal representation, converts it to the requested type, then
returns that. The internal storage remains the original type, so you
can still distinguish between how they were created.
Mike
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden