Reputation: 1485
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
Upvotes: 0
Views: 17114
Reputation: 137
Why not directly use the NSMutableDictionary
?
For example:
NSData *getData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:strURL]];
NSError *errorData;
NSMutableDictionary *dicData = [NSJSONSerialization
JSONObjectWithData:getData
options:NSJSONReadingMutableContainers
error:&errorData];
if( errorData )
{
NSLog(@"%@", [errorData localizedDescription]);
}
else {
NSString *title = [[dicData[@"items"] objectAtIndex:1] objectForKey:@"titlekey"];
NSLog(@"titlekey %@",title);
}
Upvotes: 0
Reputation: 27597
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).
Upvotes: 8