Search code examples
iphonestringnsmutablearraydidselectrowatindexpath

How do I get String value out of NSMutableArray


Code:

[self.menuList addObject:[NSDictionary dictionaryWithObjectsAndKeys:
                                       NSLocalizedString(@"PropertySubtype2fTitle", @""), 
                                       kTitleKey,
                                       publishNoOfRoomsViewController, 
                                       kViewControllerKey, nil]];

menuList is a NSMutableArray.

I want to read the PropertySubtype2fTitle localized string later in the code, like in:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

Solution

  • To fetch an entry from a NSDictionary, you can use

    [NSDictionary objectForKey:(id)keyValue]
    . To fetch an entry from a NSArray / NSMutableArray, you can use
    [NSArray objectAtIndex:(NSUInteger)index]
    . In combination and applied to your example that should be:
    NSString *title = [[menuList objectAtIndex:index] objectForKey:kTitleKey];
    whereas index would be an unsigned integer (NSUInteger).