Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert int to *NSInteger

When using this

NSInteger *myInteger = 45 ; 

I get the warning message Incompatible Integer to pointer conversion sending 'NSInteger' (aka 'int') to parameter of type 'NSInteger *' (aka 'int *') I have read another posts with same warning but did not find proper solution.

like image 291
shirjai Avatar asked Sep 20 '25 09:09

shirjai


2 Answers

NSInteger is not a subclass of NSObject as it might seem, it's a primitive type. Change your code to:

NSInteger a = 45 ; 

And (of course) do not name your variable int

like image 107
Andrey Chernukha Avatar answered Sep 22 '25 22:09

Andrey Chernukha


You should use different name then int because it is a name for a special primitive type integer. Like that you cannot name a variable with names like for, while, void... Just use another name(and you should name it to understand what it holds) like:

NSInteger myFirstInteger = 45;    

Note: In your future projects, please name your variables with a meaningful name ,so that you can create a meaningful piece of code which is easy to understand and improve.

like image 21
Ersin Sezgin Avatar answered Sep 22 '25 22:09

Ersin Sezgin