On Jun 26, 2010, at 10:52, Kyle Sluder wrote:

> On Jun 26, 2010, at 9:45 AM, Jaime Magiera <[email protected]> wrote:
> 
>> Hello,
>> 
>> The list search keeps timing out for me, and web searches are not finding 
>> anything. I can see how to tell if an NSNumber was initialized with an int 
>> or boolean (NSCFNumber vs. NSCFBoolean). However, I can't figure out how to 
>> determine if the NSNumber was initialized with an int or float.
> 
> I hope you don't mind my asking why you need to do this? The existence of 
> NSCFNumber and NSCFBoolean is an implementation detail upon which you can't 
> rely (well, probably more like shouldn't).

"Can't" is more correct than "shouldn't", in this context. The NSNumber 
documentation for 'objCType' explicitly says:

> Special Considerations
> The returned type does not necessarily match the method the receiver was 
> created with.

Incidentally, the OP is wrong in claiming that it's possible "to tell if an 
NSNumber was initialized with an int or boolean (NSCFNumber vs. NSCFBoolean)". 
This is triply wrong:

1. Unless this has changed recently, [NSNumber numberWithInt: 1] and [NSNumber 
numberWithBool: YES] both return the same (singleton) object, as do [NSNumber 
numberWithInt: 0] and [NSNumber numberWithBool: NO].

2. Testing against NSCF classes is a mistake, because they're private and 
undocumented, AFAIK.

3. As with 'objCType', the best you can determine is what type has been chosen 
to *represent* the number, not what what type was passed when creating the 
number.

In other words, NSNumber is a wrapper of numeric values, not a wrapper of C 
scalar types.


_______________________________________________

Cocoa-dev mailing list ([email protected])

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to