Question

When I try to add nsinteger value into array it shows warning,

Incompatible pointer to integer conversion sending 'NSInteger *' (aka 'int *') to parameter of type 'NSInteger' (aka 'int'); dereference with *

and crashed when reach the code

[sizary1 addObject:[NSNumber numberWithInteger:Quant.quantity]];

quantity declared as

 @property (nonatomic) NSInteger * quantity;

What change should I made?

Was it helpful?

Solution 2

1)You are using quantity as a Pointer in this case.So NSInteger doesn't allow to pointer in this case.

2)You're passing quantity to numberWithInteger:, which takes an NSInteger. It's nothing to do with the setObject:. You probably want to either copy quantity or just pass in quantity to setObject: directly.

OTHER TIPS

No need for * in NSInteger .Use

@property (nonatomic) NSInteger  quantity;

Crash

[NSNumber numberWithInteger:Quant.quantity]];

numberWithInteger: expect a value not its pointer reference so it crashes.

Make the property without * and it will work fine

You are declaring a pointer to the NSInteger. NSNumber requires the NSInteger itself, not a pointer to it. I would change your property to

@property (nonatomic) NSInteger quantity;

NSInteger is a primitive type, which means it can be stored locally on the stack. You don't need to use a pointer to access it. NSInteger is a primitive value type; you don't really need to use pointers. So your declaration should be

    @property (nonatomic) NSInteger quantity;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top