nsinteger转float,如何删除100条警告“隐式转换将失去整数精度:'NSInteger'(又名'long')为'int'”。我更新到arm64后得到了吗?...

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:

I've converted [NSNumber numberWithInt:abc]; to [NSNumber numberWithInt:(int)abc]; using find-n-replace. It fixed some.

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.

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值