4

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.

Sabir Ali
  • 475
  • 2
  • 16
  • I don't think you'll find what you're looking for. It's either fix every error (manually) or globally silence the warning. I don't see a middle ground. – trojanfoe May 14 '15 at 12:30
  • Apples has provided a ConvertCocoa64 script. Please see my answer for details. – Sabir Ali May 18 '15 at 10:11

3 Answers3

4
NSInteger a = 123;
NSString *str = [NSString stringWithFormat:@"Int:%ld", (long)a];

After updating to 64 bit need to do typecast like this((long)a). %d is only for 32 bit range %ld for long integer. For better understanding got through this apple documentation.

https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/Cocoa64BitGuide/ConvertingExistingApp/ConvertingExistingApp.html

simbesi.com
  • 1,539
  • 3
  • 17
  • 27
2

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.

Sabir Ali
  • 475
  • 2
  • 16
0

objective c implicit conversion loses integer precision 'NSUInteger' (aka 'unsigned long') to 'int

Change key in Project > Build Setting "implicit conversion to 32Bits Type > Debug > *64 architecture : No"

Other warning

Change key in Project > Build Setting "typecheck calls to printf/scanf : NO"

Explanation : [How it works]

Check calls to printf and scanf, etc., to make sure that the arguments supplied have types appropriate to the format string specified, and that the conversions specified in the format string make sense.

Hope it work

[caution: It may void other warning of 64 Bits architecture conversion].

aBilal17
  • 2,974
  • 2
  • 17
  • 23