Gulfer Gulfer - 3 months ago 12x
iOS Question

Find Dictionary Key inside and Array of Dictionaries

I have an array that holds several


Each time text fields are filled out and the submit button is pressed:

//The strings
NSString *dateString = @"Date";
NSString *timeString = @"Time";
NSString *typeString = @"Type";

- (IBAction)addData:(id)sender {

[_myDictionary setObject:_dateLabel.text forKey:dateString];
[_myDictionary setObject:_nNumber.text forKey:timeString];
[_myDictionary setObject:_type.text forKey:typeString];

[_myArray addObject:_myDictionary];

[self display]

Then I am trying to display the results in a UItextView (in this example the date) but I don't know how.


for (int i = 0; i<_myArray.count; i++) {
[_myArray objectAtIndex:i];
outputString = [outputString stringByAppendingFormat:@"%@\n",[_myDictionary objectForKey:@"Date"]];

_myTextView.text = [NSString stringWithFormat:@"%@",outputString];


This ends up displaying the date for the last Dictionary in the array. I can't even figure out how to log the date from a specific dictionary.

[_myArray objectAtIndex:3] [_myDictionary objectForKey:@"Date"]
. How would I log the date from the 3rd index?

Hope this makes sense


for (int i = 0; i<_myArray.count; i++)

outputString = [outputString stringByAppendingFormat:@"%@ %@\n",[[_myArray objectAtIndex:i]objectForKey:@"Date"], [[_myArray objectAtIndex:i]objectForKey:@"Time"]];

_myTextView.text = [NSString stringWithFormat:@"%@",outputString];


Thanks for all the quick help!!

for(int i =0 ;i <[array count];i++)
  NSLog(@"%@",[[array objectAtIndex:i]allKeys]);

this method will print all the keys