A NSDictionary
can be used as a hash map and the syntax is very simple. A NSDictionary
literal is declared using @{ }
and can contain a comma-seperated list of key-value pairs. These key-value pairs are declared as key: value
.
For example:
NSDictionary *dict = @{ @"1": @"Indore", @"2":@"Lyallpur", ... };
EDIT: To convert the string array (let's call it values) in the original question to a NSDictionary, you'd do this:
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
for (NSString *value in values) {
NSArray *keyValuePair = [value componentsSeparatedByString:@"$"];
[dict setObject:keyValuePair[1] forKey:keyValuePair[0]];
}