How do I convert NSUInteger
value to int
value in objectiveC?
and also how to print NSUInteger
value in NSLog
, I tried %@,%d,%lu
these are not working and throwing Ex-Bad Access error.
Thank you
NSUInteger intVal = 10; int iInt1 = (int)intVal; NSLog(@"value : %lu %d", (unsigned long)intVal, iInt1);
for more reference, look here
Explicit cast to int
NSUInteger foo = 23; int bar = (int)foo;
Although
NSLog(@"%lu",foo);
will work OK on current builds of OSX. It's not safe, as NSUInteger is typedeffed as unsigned int on other builds. Such as iOS. The strict answer is to cast it first:
NSLog(@"%lu",(unsigned long)foo);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With