Do NSDouble, NSFloat, or other types than NSInteger exist? Do NSDouble, NSFloat, or other types than NSInteger exist? objective-c objective-c

Do NSDouble, NSFloat, or other types than NSInteger exist?


NSInteger exists because the int type varies in size between 32-bit and 64-bit systems. float and double don't vary in size the same way, so there's no need to have wrapper types for them.


There is no NSFloat but I know the Core Graphics API eventually changed from float to CGFloat so that it could use a double on some architectures.

It is best to use the exact types that API headers declare. This makes type changes automatic if you ever recompile your code for a different target.


It's also about conventions.

A typedef to an int is incompatible to int int itself.

Example: pid_t is of type int, but passing an int would create a warning.

Why? Because you want to be sure that if you cross API boundaries everyone knows what the code expects.

There are float and double types, i.e NSTimeInterval. It's not really about the underlying type, but the convention to adhere to.

If you declare a local int as a loop counter and you do not plan to pass it to a well-defined API, it's fine to call an int an int.