警告:隐式转换在xcode 6中丢失整数精度 [英] Warning: Implicit conversion loses Integer precision in xcode 6

查看:376
本文介绍了警告:隐式转换在xcode 6中丢失整数精度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道它可能是重复的,但是在将xcode更新为版本6后,我的ios项目中有大约30个隐式转换丢失了整数精度警告。

I know it could be a duplicate, but i got about 30 Implicit conversion loses Integer precision warnings in my ios project after updating xcode to version 6.

第一个例子:

NSArray * stations = [self stationsJSON][KEY_ITEM_LIST];

int newSize = (stations.count + 1); // Implicit conversion loses Integer precision: 'unsigned long' to 'int'

第二个例子:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    ...
    int index = indexPath.row / 2; // Implicit conversion loses Integer precision: 'long' to 'int'
    ...
}

我知道警告意味着什么。使用NSInteger可以帮助避免此警告。

I know what the warning means. Using NSInteger can help to avoid this warning.

我不明白,为什么xcode 5中没有警告?为什么在更改线后没有警告

I don't understand, why there was no warnings in xcode 5? And why there is no warning after i change the line

int index = indexPath.row / 2;

int index = indexPath.row / 2i;


推荐答案

NSArray计数 NSUInteger

NSIndexPath行 NSInteger

在64位系统上, NSUInteger NSInteger 是64位,但 int 是32位。所以该值不适合导致警告。

On 64-bit systems, NSUInteger and NSInteger are 64-bits but int is 32-bit. So the value won't fit which results in the warning.

最好在iOS中避免 int 。相反,使用与您正在处理的值相同的类型。

It's best to avoid int in iOS. Instead, use the same type as the values you are dealing with.

NSInteger index = indexPath.row / 2;

由于默认警告,你可能会在Xcode 6中看到这些。您可以使用正确的警告设置在Xcode 5中轻松查看这些内容并构建为64位。

You probably see these in Xcode 6 due to the default warnings. You can easily see these in Xcode 5 with the right warning settings and building for 64-bit.

这篇关于警告:隐式转换在xcode 6中丢失整数精度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆