I think the actual layout you want is:
NSDictionary {
Unique Value: NSDictionary {
"Key2": ValueABC
"Key3": ValueDEF
}
Unique Value: NSDictionary {
"Key2": ValueFGH
"Key3": ValueJKL
}
Unique Value: NSDictionary {
"Key2": ValueRST
"Key3": ValueXYZ
}
}
Basically, rather than storing the unique key/value pair inside the dictionary, have a new dictionary where the unique value is the key to the other data. If your unique value is an NSString
then you'll find you'll probably get close to O(1) time complexity.
You can convert your set to the above layout using the following code:
NSMutableDictionary *searchable = [NSMutableDictionary dictionary];
for (NSDictionary *dict in MySet)
[searchable setObject:dict forKey:[dict objectForKey:@"Unique-Identifier-Key"]];
(although it would be better to load the data directly into the structure described above rather than converting it from a set). Then, whenever you want to find one of your dictionaries:
NSDictionary *dict = [searchable objectForKey:idSearched];