Jef*_*rey 93 cocoa objective-c nsinteger
例如,将value消息传递给NSInteger类似的实例时
[a value] 它会导致EXC_BAD_ACCESS.
那么如何转换NSInteger为int?
如果相关,则只使用小于32的小数.
Dav*_*ong 198
塔达:
NSInteger myInteger = 42;
int myInt = (int) myInteger;
Run Code Online (Sandbox Code Playgroud)
NSInteger只不过是32/64位int.(它将根据您正在运行的操作系统/平台使用适当的大小)
Sam*_*lay 28
如果你想这样做在线,只投中NSUInteger或NSInteger到int:
int i = -1;
NSUInteger row = 100;
i > row // true, since the signed int is implicitly converted to an unsigned int
i > (int)row // false
Run Code Online (Sandbox Code Playgroud)
Abi*_*ern 18
我不确定你需要将一个转换NSInteger为一个的情况int.
NSInteger只是一个typedef:
NSInteger用于描述整数,与您是为32位还是64位系统构建无关.
#if __LP64__ || TARGET_OS_EMBEDDED || TARGET_OS_IPHONE || TARGET_OS_WIN32 || NS_BUILD_32_LIKE_64
typedef long NSInteger;
#else
typedef int NSInteger;
#endif
Run Code Online (Sandbox Code Playgroud)
你可以使用NSInteger你使用的任何地方int而不转换它.