Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why am I getting an integer to pointer conversion error in objective-c?

I am looping through an NSString object called previouslyDefinedNSString and verifying if the integer representing the ASCII value of a letter is in an NSMutableSet called mySetOfLettersASCIIValues, which I had previously populated with NSIntegers:

NSInteger ASCIIValueOfLetter;

    for (int i; i < [previouslyDefinedNSString length]; i++) {

        ASCIIValueOfLetter = [previouslyDefinedNSString characterAtIndex:i];

        // if character ASCII value is in set, perform some more actions...
        if ([mySetOfLettersASCIIValues member: ASCIIValueOfLetter])

However, I am getting this error within the condition of the IF statement.

Incompatible integer to pointer conversion sending 'NSInteger' (aka 'int') to parameter of type 'id';
Implicit conversion of 'NSInteger' (aka 'int') to 'id' is disallowed with ARC

What do these errors mean? How am I converting to an object type (which id represents, right?)? Isn't NSInteger an object?

like image 653
Justin Copeland Avatar asked Apr 01 '12 03:04

Justin Copeland


1 Answers

You want to make it an NSNumber, as in:

NSInteger ASCIIValueOfLetter;

    for (int i; i < [previouslyDefinedNSString length]; i++) {

        ASCIIValueOfLetter = [previouslyDefinedNSString characterAtIndex:i];

        // if character ASCII value is in set, perform some more actions...
        if ([mySetOfLettersASCIIValues member: [NSNumber numberWithInteger: ASCIIValueOfLetter]])

Now you're going to have the result you're looking for.

like image 184
Maurício Linhares Avatar answered Oct 05 '22 22:10

Maurício Linhares