I have a question about safely or properly converting an NSString into types such as CGFloat and NSInteger, considering that these are simply wrapper types that Apple created to use different primitives depending on certain factors (e.g., NSInteger is typedef'd to int on 32-bit architectures and long on 64-bit architectures).
For example, I know I can use something like [ someString intValue ] or [ someString longValue ], but how do I instead say that I want someString to become an NSInteger, allowing the precision of the underlying primitive to be chosen by the compiler? Saying something like NSInteger integer = [ someString intValue ] would result in data loss if someString was created from an NSInteger on a 64-bit system, right? What's the best way to deal with this situation?
Use integerValue instead. And getting an int will only cause a problem if the integer represented by the string is greater than the 32-bit INT_MAX, but it's still better to use the more compatible method.
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