Enam Ajmal Enam Ajmal - 1 year ago 81
Objective-C Question

Store user input in array objective-c

i am trying to get input from user and want to store it in an array.

int main(int argc, const char * argv[]) {
int i;
char name[10];
NSMutableArray *myarray=[[NSMutableArray alloc]init];
for (i=0; i<10; i++)

[myarray addObject:i];

return 0;


You are trying to insert a non Object in NSMutableArray.

NSMutableArray can store objects only,

char and int are data types of c language which are not treated as objects in Objective C.

First you need to convert them into objects then You can insert.

Try with this:

 [myarray addObject:@(i)]; or
 [myarray addObject:[NSNumber numberWithInt:i]];

 for name:

 [NSString stringWithFormat:@"%c",name]