objective c - NSDictionary: Store 3 float values for every key -
how can this? want store rgb color values can retrieved in response color name. c++ code uses boost unordered_map this:
("slateblue1", color(0.5137f, 0.4353f,1.0f)) ("tan3", color(0.8039f, 0.5216f, 0.2471f)) ("grey32", color(0.3216f, 0.3216f, 0.3216f))
color class stores 3 values. trying in objective-c tying me in knots , weird errors! of dictionary examples i've found matching 2 strings. of course can use c++ code in .mm file, if has ideas how achieve obj-c way, i'd pleased learn, thanks.
it's same in cocoa - use nsdictionary instead of unordered_map, nsstring instead of const char* key , uicolor instead of color object , you're done.
e.g., [nsdictionary dictionarywithobject: [uicolor redcolor] forkey: @"red"]]
create single-entry map. adjust multiple colors , you're set. use nscolor if you're not on ios.
you might missing key point dictionary (almost) untyped collection, can store heterogenous set of object types using heterogenous set of key types.
Comments
Post a Comment