NSMutableArray *output = [[NSMutableArray alloc]init];
or
NSArray *output = [[NSMutableArray alloc]init];
I can set keys and values. Now, I just want to access each key and value, but I don't know the number of keys set.
In PHP it is very easy, something as follows:
foreach ($output as $key => $value)
How is it possible in Objective-C?
I think you are confused with NSDictionary with NSArray.
In NSDictionary you can set the object with the keys like
NSMutableDictionary *output = [[NSMutableDictionary alloc]init];
[yourDictionary setObject:@"yourvalue" forKey:@"yourKey"];
and you can get the object like
[yourDictionary objectForKey:@"yourKey"];
In your Array it just adds the object in the index.
NSArray * output = [[NSArray alloc] initWithObjects:@"option1",@"option2", nil];
get the object as
[output objectAtIndex:1]; // 1 is the index number
Use NSDictionary that manages keys and values
For an NSArray:
for (id item in output) {
// go nuts
}
For an NSDictionary:
for (id key in output) {
id value = [output objectForKey:key];
// go nuts
}
I'm using the generic id
type because I don't know what types of keys and values you are working with. You should use the specific class names if you know them.
In your example take a second array for the value objects and use a NSDictionary:
NSDictionary *dic = [[NSDictionary alloc] initWithObjects: objectsArray
forKeys: output];