NSString *one = [NSDictionary dictionaryWithObjectsAndKeys:@"1",@"id",@"Test1",@"text", nil];
NSString *two = [NSDictionary dictionaryWithObjectsAndKeys:@"2",@"id",@"Test2",@"text", nil];
NSString *three = [NSDictionary dictionaryWithObjectsAndKeys:@"3",@"id",@"Test3",@"text", nil];
_options = [NSArray arrayWithObjects:one,two,three,nil];
This is the code i am using and running properly in my code. Now i want it dynamically, like
int total = 20;
NSMutableArray *arr = [[NSMutableArray alloc] init];
for(int x = 0; x < total; x++)
{
[arr addObject:[NSDictionary dictionaryWithObjectsAndKeys:@"1",@"id",@"Test1",@"text", nil]];
}
But it’s not working. Can anyone help me out of this.
The main code is like
_options = [NSArray arrayWithObjects:[NSDictionary dictionaryWithObjectsAndKeys:@"1",@"id",@"Test1",@"text", nil],[NSDictionary dictionaryWithObjectsAndKeys:@"1",@"id",@"Test1",@"text", nil],[NSDictionary dictionaryWithObjectsAndKeys:@"1",@"id",@"Test1",@"text", nil],nil];
and i want to create it dynamically ,like the value will go for 1-100. How can i do that
You probably ran into an issue trying to put primitives into the NSDictionary, which isn’t possible. Turn your values into strings.