Globas techn
Globas techn

Reputation: 95

Nsinteger accessible issue

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?

Upvotes: 0

Views: 286

Answers (4)

SAMIR RATHOD
SAMIR RATHOD

Reputation: 3510

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;

Upvotes: 0

Dharmbir Singh
Dharmbir Singh

Reputation: 17535

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.

Upvotes: 0

Lithu T.V
Lithu T.V

Reputation: 20021

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

Upvotes: 1

hvanbrug
hvanbrug

Reputation: 1301

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;

Upvotes: 0

Related Questions