• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How to add a -(unsigned long long)unsignedLongLongValue method to NSString
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to add a -(unsigned long long)unsignedLongLongValue method to NSString


  • Subject: Re: How to add a -(unsigned long long)unsignedLongLongValue method to NSString
  • From: Ken Thomases <email@hidden>
  • Date: Sun, 11 Jan 2009 00:58:38 -0600

On Jan 11, 2009, at 12:24 AM, email@hidden 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.

Do you really need to exceed the long long range? NSString does support -longLongValue.



  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 ?

Definitely don't write your own parser that way. If you can, use NSScanner or sscanf. If you must work character-by-character, use character constants (e.g. '0' or '9') rather than the specific numeric Unicode code point values.


However, in this case you avoid even that.  You can use something like:

[[NSDecimalNumber decimalNumberWithString:aString] unsignedLongLongValue]

You could also use a NSNumberFormatter. Associate it with your NSTextField. Then, you can retrieve an NSNumber using the - objectValue method of the control, and ask it for its - unsignedLongLongValue.

Cheers,
Ken

_______________________________________________

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


  • Follow-Ups:
    • Re: How to add a -(unsigned long long)unsignedLongLongValue method to NSString
      • From: email@hidden
References: 
 >How to add a -(unsigned long long)unsignedLongLongValue method to NSString (From: email@hidden)

  • Prev by Date: Re: How to add a -(unsigned long long)unsignedLongLongValue method to NSString
  • Next by Date: Re: How to add a -(unsigned long long)unsignedLongLongValue method to NSString
  • Previous by thread: Re: How to add a -(unsigned long long)unsignedLongLongValue method to NSString
  • Next by thread: Re: How to add a -(unsigned long long)unsignedLongLongValue method to NSString
  • Index(es):
    • Date
    • Thread