I'm a noob to objective-c and I'm trying to create a dictionary with
key:string and value:<string, string>.
I'm a noob to objective-c and I'm trying to create a dictionary with
key:string and value:<string, string>.
The best way to create a dictionary is to use the NSDictionary
class.
NSDictionary *dict = @{@"key0": @"val0",
@"key1": @"val1"};
There is also a mutable variation called NSMutableDictionary
that you can append.
To access elements in your dictionary, you subscript like so
NSString *val = dict[@"key0"];
The dictionary can store any sort of NSObject
subclass as values.
EDIT:
I missed the part where you want to store a "tuple". You can use an array to do this
NSDictionary *dict = @{@"key0": @[@"val0", @"val1"],
@"key1": @[@"val2", @"val3"]};
EDIT2
NSMutableDictionary *dict = [@{@"key0": @[@"val0", @"val1"],
@"key1": @[@"val2", @"val3"]} mutableCopy];
dict[@"key2"] = @[@"val10", @"val11"];
You may create custom pair class
@interface Pair : NSObject
@property (nonatomic, strong) NSString *first;
@property (nonatomic, strong) NSString *second;
@end