Hi all,
I want to know if this assignment is correct
id var = 9;
Will var be assigned the value 9 or do we have to wrap in some wrapper class like NSNumber?
Hi all,
I want to know if this assignment is correct
id var = 9;
Will var be assigned the value 9 or do we have to wrap in some wrapper class like NSNumber?
It is possible, but it is not correct:
warning: initialization makes pointer from integer without a cast
An id
is a pointer to an object, not an integer.
id
container to carry an integer? You should use NSNumber
instead.9 is an integer literal, which is not an object. id
is a pointer to an object. If you need to pass an integer as an object (type id
) you have to wrap it inside a NSNumber
object like this:
id var = [NSNumber numberWithInteger: 9];