如何删除 100 条警告“隐式转换失去整数精度:'NSInteger'(又名'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?

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

问题描述

问题:

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

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.

我尝试过的:

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

  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.

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

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

问题:

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

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.

提前致谢.

推荐答案

如果其他人也面临类似的情况,我想澄清一下如何处理.尽管@Raju 的回答建议手动进行(我想避免这样做),但我在他分享的链接中找到了我需要的内容.

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 提供了一个名为 ConvertCocoa64 的 64 位转换脚本,位于/Developer/Extras/64BitConversion/ConvertCocoa64,它不仅将所有 int 转换为 NSInteger 它还处理float 到 CGFloat 的转换,如下所述:

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:

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

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.

请参考这个完整详情的链接.它不仅解释了如何使用脚本,而且还建议了一些非常重要的 64 位迁移后检查点.

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'(又名'long')到'int'"更新到 arm64 后我得到了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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