I’m trying to figure out how to set array with variables of other class. I have NSObject class named myObject, where I did declare variables myInt and mySecondInt of int type.
Then I import myObject and tried to set an array like this:
MyObject *object = [[MyObject alloc]init];
object.myInt = 50;
object.mySecondInt = 15;
object.array = [[NSArray alloc]initWithObjects:object.mySecondInt,object.myInt, nil];
And then I got an error: implicit conversion of 'int' to 'id' is disallowed with arc
Please help me to solve this, I’m learning objective-c and I wish to know how to manage with variables of other class.
NSArrayholds the objects, myInt and mySecondInt are int values, not an object. You can typecast it intoNSNumberorNSString. If you typecast it intoNSStringthen access itsintValuewhen using it.Another way is to add the whole object in the array & then retrieve the object from the array & then access its entities which is better solution instead of adding individual entity.