Question

I'm updating an old project of mine. I'm doing good progress and everything goes smooth.

Yesterday when I finished working everything was ok with my project, no errors, no warnings.

Suddenly, when today I started the project and without pressing a single key, I got 23 warnings at once. All of them are:

Implicit conversion loses integer precision: 'NSInteger' (aka 'long') to 'int'

Has somebody experienced something similar? why the hell was yesterday all OK and today I have sucha mess?

Edit. Here is some example:

- (IBAction)previousText:(UIBarButtonItem *)sender {


    int i=[self.indexPathArray indexOfObject:[self indexPathForActiveText]];

    if (i>0) {

        [self moveRows:i-1];


    }

}

Edit It turns out that (I don't know why) the simulator I was using was iPhone retina (64 bit). I changed back to iPhone 3.5 inches (32 bit) and all the warnings went away.

Now the thing is, how do I make it compatible for both devices?

Was it helpful?

Solution

Don't use primitive C-types like int/unsigned and instead use the Objective-C types like NSInteger/NSUInteger.

These warnings will then disappear as the type sizes change depending on architecture.

Things get more interesting when you use printf-like functions as you will need to conditionally compile the formatting string, depending on architecture; for example:

NSInteger i = 1;
#if __LP64__
NSLog(@"i is %ld", i);
#else
NSLog(@"i is %d", i);
#endif

However, better (when the formatting statement is non-trivial):

NSInteger i = 1;
NSLog(@"i is %ld", (long)i);

OTHER TIPS

64bit warning.

NSInteger i=[self.indexPathArray indexOfObject:[self indexPathForActiveText]];

You probably updated your xcode. The latest turned on a lot of warnings for when you're compiling against say an iphone 5s or ipad air (x86_64)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top