Pra*_*sad 14 int cocoa types objective-c nsinteger
我们可以使用int和NSInteger互换吗?是否有任何具体情况只能使用NSInteger,而不是使用int?
Jer*_*myP 20
我们可以互换使用int和NSInteger吗?
在Apple使用的LP64架构上,对于现代OS X Cocoa,NSInteger是64位宽.这意味着如果将NSInteger转换为int,则与NSNotFound的比较可能会失败.这是一个例子:
NSRange theRange = [@"foo" rangeOfString @"x"];
int location = theRange.location;
if (location == NSNotFound) // comparison is broken due to truncation in line above
{
// x not in foo
}
Run Code Online (Sandbox Code Playgroud)
在我看来,你应该只使用NSInteger你需要的地方将参数传递给Cocoa或从Cocoa接收结果,文档说数据类型是NSInteger.在所有其他情况下:
int或long.stdint.h类型,例如int32_t,int64_t.intptr_t或uintptr_t| 归档时间: |
|
| 查看次数: |
15197 次 |
| 最近记录: |