ios - NSInteger和int到底什么区别分别用在什么场景
黄舟
黄舟 2017-04-17 11:03:31
0
1
469

看官方给出的示例代码,一般用于计算的,返回的整数都是用 NSInteger的,但是一般for循环的计数器就都是int了

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
for (int i=0; i<10; i++) {}

我看一些资料说NSInteger是架构安全的,但这种架构安全主要体现在哪里呢?
如果用int会在哪些情况下出现不安全的问题呢?
为什么for循环计数器都用int,不会出问题吗?
NSInteger对比int会有性能上的或者其他的损失吗?
。。。我好像十万个为什么啊 -_-||

黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

reply all (1)
刘奇
#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

这是NSInteger的定义
对于不同平台32,64位有不同的最大值(int long)。
可以直接转化。
所以mac os或者ios上的系统api都是使用NSInteger作为参数。

    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!