Reputation: 147
I am attempting to take an array called _operationArray that has NSNumbers stored within it. I want to take the last two elements of the array and add them together. In the following code, endObject should be the last element space in the array, secondToEndObject should be the second to last element space. I then attempt to
int singleSpace = 1;
int doubleSpace = 2;
NSUInteger endObject = [_operationArray count] - singleSpace;
NSUInteger secondToEndObject = [_operationArray count] - doubleSpace;
NSUInteger *firstNumber =[[_operationArray objectAtIndex:endObject] integerValue] ;
NSUInteger *secondNumber = [[_operationArray objectAtIndex:secondToEndObject]
integerValue];
/* These two lines defining first and second Number both have warnings saying: Incompatible integer to pointer conversion initializing 'NSUInteger *' (aka 'unsigned int *') with an expression of type 'NSInteger' (aka 'int')*/
_theResult = firstNumber + secondNumber;
/* This last line has a error saying: Invalid operands to binary expression ('NSUInteger *' (aka 'unsigned int *') and 'NSUInteger *')*/
I'm incredibly new to Objective-C and Xcode, so I don't even understand what these errors actually mean. Any help would be appreciated.
Upvotes: 0
Views: 801
Reputation: 14068
I guess you shoudl get rid of the asterisk.
NSUInteger firstNumber =[[_operationArray objectAtIndex:endObject] integerValue] ;
NSUInteger secondNumber = [[_operationArray objectAtIndex:secondToEndObject]
integerValue];
integerValue
returns an NSUInteger
(aka unsigned int
) and not a pointer to it.
BTW, it returns an NSInteger
. Meaning you may run into issues if the value returned is negative.
Upvotes: 1