如何删除100个警告“隐式转换将失去整数精度:将'NSInteger'(aka'long')转换为'int'''.我更新到arm64后得到了吗? [英] How to remove 100s of warnings "implicit conversion loses integer precision: 'NSInteger' (aka 'long') to 'int'" I got after updating to arm64?

查看:337
本文介绍了如何删除100个警告“隐式转换将失去整数精度:将'NSInteger'(aka'long')转换为'int'''.我更新到arm64后得到了吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:

昨天,我转换了一个大型项目来支持 arm64 ,此后,我立即收到了500多个警告.其中大约70%是将NSInteger分配给int的位置,反之亦然,其余的是NSUInteger用NSString格式化的位置,如下所示:

NSInteger a = 123;
NSString *str = [NSString stringWithFormat:@"Int:%d", a]; //warning: value of 'NSInteger' should not be used as formate argument; add an explicit cast to 'unsigned long' instead.

现在,我确实知道如何手动处理它们,但这是一项艰巨的任务,而且非常费力. 我还知道我可以一起使类型不匹配警告完全消失,但是我不想这样做.当然,它们非常有帮助.

我尝试过的事情:

  1. 我已经使用find-n-replace将[NSNumber numberWithInt:abc];转换为[NSNumber numberWithInt:(int)abc];.它修复了一些.
  2. 我还尝试将所有int属性更改为NSInteger属性 但是它使警告的数量增加了一倍(达到900多个).所以我 恢复.

  3. 我也试图找到一些正则表达式,但找不到 一些适合我需要的东西.

问题:

我正在寻找正则表达式或有人尝试过的其他解决方法,这些方法可以减少手动修复它们所需的工作量.

谢谢.

解决方案

如果其他人也遇到类似的情况,我想澄清一下如何处理.尽管@Raju的答案建议手动执行(我想避免这样做),但我在他共享的链接中找到了我真正需要的东西.

Apple提供了一个名为ConvertCocoa64的64位转换脚本,位于/Developer/Extras/64BitConversion/ConvertCocoa64,该脚本不仅将所有int转换为NSInteger,而且还处理了float到CGFloat的转换,如下所述:

它将大多数int和unsigned int实例转换为NSInteger和 NSUInteger,分别.它不会在位域中转换整数 声明和其他不适当的情况.在处理过程中, 脚本引用了硬编码的例外列表.

除了上述转换外,它还会标记代码中需要手动修复的行.因此,这可能有助于处理字符串格式的警告.

请参考链接以获取完整的详细信息.它不仅说明了如何使用脚本,还建议了一些非常重要的64位迁移后检查点.

Problem:

Yesterday I converted a large project of mine to support arm64 and after that I got 500+ warnings at once. About 70% of them are where NSInteger is being assigned to int or vice versa, and remaining are where NSUInteger is formatted in NSString like this:

NSInteger a = 123;
NSString *str = [NSString stringWithFormat:@"Int:%d", a]; //warning: value of 'NSInteger' should not be used as formate argument; add an explicit cast to 'unsigned long' instead.

Now I do know how to adress them manually, but that's a huge task and very laborious. I'm also aware that I can silence the type mismatch warnings all together, but I don't want to do that. Of course, they're very helpful.

What I've tried:

  1. I've converted [NSNumber numberWithInt:abc]; to [NSNumber numberWithInt:(int)abc]; using find-n-replace. It fixed some.
  2. I've also tried to change all my int properties to NSInteger properties but it doubled the number of warnings (reached to 900+ count). So I reverted.

  3. I've also tried to find some regular expression but couldn't find something suitable to my needs.

Question:

I'm looking for a regular expression or any other workaround somebody has tried which can reduce the amount of work needed to fix them manually.

Thanks in advance.

解决方案

In case someone else's facing a similar situation, I want to clarify how to deal with it. Although @Raju's answer is suggesting to do it manually (which I wanted to avoid), I found exactly what I needed at the link he shared.

Apple has provided a script for 64bit conversion called ConvertCocoa64, located at/Developer/Extras/64BitConversion/ConvertCocoa64 which not only converts all int to NSInteger it also deals with float to CGFloat conversion, as stated:

It converts most instances of int and unsigned int to NSInteger and NSUInteger, respectively. It doesn't convert ints in bit-field declarations and other inappropriate cases. During processing, the script refers to a hardcoded list of exceptions.

In addition to above conversions it also flags the lines in code which need manual fix. So this might help with the warnings of String Formats.

Please refer to this link for complete details. It not only explains how to use the script but also suggests some very important post 64-bit migration check points.

这篇关于如何删除100个警告“隐式转换将失去整数精度:将'NSInteger'(aka'long')转换为'int'''.我更新到arm64后得到了吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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