On Sun, Jan 11, 2009 at 12:24 AM,  <ewan.dela...@math.unicaen.fr> wrote:
>   I have a Cocoa app that performs some computations on
> large integers (but still in the "unsigned long long" range), some
> of which are entered by the user in a NSTextField.
>
>  The problem , of course, is that NSControl has no
>  -(unsigned long long)unsignedLongLongValue method, and
> as specified in the documentation, if the user writes too many digits
> the -(int)intValue method just returns UINT_MAX.
>
>   It seems logical to deal with this problem by calling the
> -(NSString*)stringValue method of NSControl, and implementing
> a  -(unsigned long long)unsignedLongLongValue method for
> NSString.
>
>   This is what I did in my project, using the code below. I can't
> help feeling that this code is dirty because it relies on the character
> for the "j" digit being indexed as unichar number j+48. Can anyone
> tell me what would be the clean way to do this ?

Take a look at +[NSDecimalNumber decimalNumberWithString:]

<http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSDecimalNumber_Class/Reference/Reference.html#//apple_ref/doc/uid/20000179-decimalNumberWithString_>

Since it is a subclass of NSNumber, it implements unsignedLongLongValue.
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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 arch...@mail-archive.com

Reply via email to