iosobjective-cnsuinteger

I can't seem to divide NSUInteger by 2


The snippet of code:

NSUInteger *lengthOfLine =100;
NSUInteger *half = lengthOfLine/2;

The compile error for line 2:

Invalid operands to binary expression ('NSUInteger *' (aka 'unsigned long *') and 'int')

Solution

  • you should use NSUInteger, not NSUInteger *. NSUInteger is a primitive type, not a subclass of NSObject. Now you're dealing with a pointer to NSUInteger