I was recently writing a program in Objective-C and I tried the wrote the following part of a line where 'someString' is an instance of NSString:
[someString substringFromIndex:3];
The compiler seems okay with this but I'm not exactly sure why. The documentation for the substringFromIndex method says that the parameter has to be an NSUInteger however, isn't 3 just a primitive integer? Why can I do this? (Note, I'm new to Objective-C so I'm sure the reasoning is very simple or I'm just wrong about something.)
NSUInteger is typedef'd to a primitive type. Which type it is depends on the processor you're compiling for.
As seen here (and pasted below):
#if __LP64__ || TARGET_OS_EMBEDDED || TARGET_OS_IPHONE || TARGET_OS_WIN32 || NS_BUILD_32_LIKE_64
typedef unsigned long NSUInteger;
#else
typedef unsigned int NSUInteger;
#endif
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