2

Possible Duplicate:
Storing and retrieving unsigned long long value to/from NSString

I am trying to create a unsigned long long from a string so I can use the value in elsewhere but not having much luck doing so...Here is what I am using to attempt this

-(void)unsignedLongValue{


NSString *theString = [NSString stringWithFormat:@"%llu", [NSNumber   
unsignedLongLongValue]];    

theString = [[_message objectForKey:@"user"] objectForKey:@"id"];    

NSLog(@"%llu");

}

If you have any suggestions or know of any good articles I would be very much appreciative if you could inform me! thanks!

Community
  • 1
  • 1
FreeAppl3
  • 858
  • 1
  • 15
  • 32
  • check this thread http://stackoverflow.com/questions/1181637/storing-and-retrieving-unsigned-long-long-value-to-from-nsstring – Felipe Sabino Jun 23 '11 at 02:41
  • To request support for reading unsigned values from NSString, please visit http://bugreport.apple.com and file a dupe of radar://2264733 against component `Foundation | X`. – Quinn Taylor Jan 23 '13 at 05:49

2 Answers2

5

You probably want to do this,

NSString * theString = [[[_message objectForKey:@"user"] objectForKey:@"id"];

NSNumberFormatter * numberFormatter = [[[NSNumberFormatter alloc] init] autorelease];
NSNumber * number = [numberFormatter numberFromString:theString];

NSLog(@"%llu", [number unsignedLongLongValue]);
Deepak Danduprolu
  • 44,595
  • 12
  • 101
  • 105
2

The line

NSLog(@"%llu");

does nothing. You need to tell the log what to print, not just what type it is. Use this instead:

NSLog(@"%llu",numberToPrint);

Also, you re-write theString immediately after defining it, so the initial value from

NSString *theString = [NSString stringWithFormat:@"%llu", [NSNumber unsignedLongLongValue]]; 

is never used.

PengOne
  • 48,188
  • 17
  • 130
  • 149
  • One more thing about the last part, instance method is being called on a class. – Deepak Danduprolu Jun 23 '11 at 02:45
  • @Deepak: Yes, his code is a wash. Hence why I voted up your re-write. You might be kind and explain why your way is so much better. – PengOne Jun 23 '11 at 02:47
  • These are all great responses! I appreciate the help, I am going to try a few things you suggested and will let you all know how things went! Thanks agin – FreeAppl3 Jun 23 '11 at 03:05