0

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?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Globas techn
  • 95
  • 1
  • 6

4 Answers4

1

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

Lithu T.V
  • 19,955
  • 12
  • 56
  • 101
0

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.

Dharmbir Singh
  • 17,485
  • 5
  • 50
  • 66
  • It is perfectly valid to have pointers to NSInteger values. It's not appropriate in this case but it is allowed. – rmaddy May 23 '13 at 05:34
0

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;
hvanbrug
  • 1,291
  • 2
  • 12
  • 25
0

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;
SAMIR RATHOD
  • 3,512
  • 1
  • 20
  • 45