Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I'm getting comparison between pointer and integer

static NSInteger *previousPage = 0;

    CGFloat pageWidth = scrollView.frame.size.width;

    float fractionalPage = scrollView.contentOffset.x/pageWidth;

    NSInteger page = lround(fractionalPage);
    if(previousPage != page){ //page has changed

        previousPage = page;
    }

I'm getting the error for the previousPage != page condition

Also, the previousPage = page is giving me "incompatible integer to pointer conversion..."

like image 246
Adam Avatar asked Mar 22 '26 03:03

Adam


1 Answers

You have the declaration

static NSInteger *previousPage = 0;

in your code, which declares previousPage to be a pointer to an integer (not an integer), and initializes it to the null pointer (not the value 0 zero).

In

if(previousPage != page){ //page has changed

    previousPage = page;
}

you compare the pointer value of previousPage to the integer value of page, hence the error. Simple drop the * in the declaration of previousPage.

static NSInteger previousPage = 0;
like image 118
Dirk Avatar answered Mar 23 '26 18:03

Dirk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!