What is the maximum value of NSInteger?
The maximum value of an NSInteger is NSIntegerMax.
The maximum value of an NSInteger is NSIntegerMax.
In such cases you might right click and go to definition: #if __LP64__ || (TARGET_OS_EMBEDDED && !TARGET_OS_IPHONE) || TARGET_OS_WIN32 || NS_BUILD_32_LIKE_64 typedef long NSInteger; typedef unsigned long NSUInteger; #else typedef int NSInteger; typedef unsigned int NSUInteger; #endif
There is now NS_ENUM starting Xcode 4.5: typedef NS_ENUM(NSUInteger, NSCellType) { NSNullCellType = 0, NSTextCellType = 1, NSImageCellType = 2 }; And you can consider NS_OPTIONS if you work with binary flags: typedef NS_OPTIONS(NSUInteger, MyCellFlag) { MyTextCellFlag = 1 << 0, MyImageCellFlag = 1 << 1, };
For an int index: NSIndexPath *path = [NSIndexPath indexPathWithIndex:index]; Creates Index of the item in node 0 to point to as per the reference. To use the indexPath in a UITableView, the more appropriate method is NSIndexPath *path = [NSIndexPath indexPathForRow:row inSection:section];
NSInteger is a primitive type, which means it can be stored locally on the stack. You don’t need to use a pointer to access it, but you can if you want to. The line: NSInteger *processID = [[NSProcessInfo processInfo] processIdentifier]; returns an actual variable, not its address. To fix this, you need to remove the … Read more
NSNumber is a class, not a primitive, and is used when you need to put raw numbers into dictionaries, arrays, or otherwise encapsulate them. NSInteger, NSUInteger, CGFloat, etc are simple types and correspond (on 32-bt systems like the iPhone) to int, unsigned int and float. As a general rule, if you need to store a … Read more
You cannot cast it because NSInteger is not an object, just an alias for a built-in type. You can always create a new NSNumber object from NSInteger, like this: NSNumber *myNum = @(myNsIntValue); or in the prior version of the compiler, use NSNumber *myNum = [NSNumber numberWithInteger:myNsIntValue];
From http://pubs.opengroup.org/onlinepubs/009695399/functions/printf.html: z Specifies that a following […] conversion specifier applies to a size_t or the corresponding signed integer type argument; t Specifies that a following […] conversion specifier applies to a ptrdiff_t or the corresponding unsigned type argument; And from http://en.wikipedia.org/wiki/Size_t#Size_and_pointer_difference_types: size_t is used to represent the size of any object (including arrays) in … Read more
If the string is a human readable representation of a number, you can do this: NSInteger myInt = [myString intValue];
Ta da: NSInteger myInteger = 42; int myInt = (int) myInteger; NSInteger is nothing more than a 32/64 bit int. (it will use the appropriate size based on what OS/platform you’re running)