iosobjective-cintnsinteger

Implicit conversion loses integer precision: warning, code for 64-bit platform


after getting a lot of warnings when changing (by accident) the simulator (from 32 to 64 bit platforms), I'm getting rid of all the int declaration and changing those for NSintegers.

But I have another warning in this piece of code:

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

    NSInteger i=[self.indexPathArray indexOfObject:[self indexPathForActiveText]];
    //before it was int i=... 

    if (i<[self.indexPathArray count]-1) {

        [self moveRows:++i];
    }
}

however on the line [self moveRows:++i]; I get this warning again:

'implicit conversion loses integer precision:...'


Solution

  • It should show warning in 64-bit platform. NSInteger i=[self.indexPathArray indexOfObject:[self indexPathForActiveText]]; Because indexOfObject: return NSUInteger. So your code should be as below

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

    And also

    -(void)moveRows:(NSUInteger)index;
    

    See this apple's doc