nsdictionary - iPhone - Changing a sub-sub-sub NSMutableDictionary value -
if have data tree :
nsmutabledictionary (dict1) nsmutabledictionary (dict2) nsmutablearray (array) nsmutabledictionary (dict3) key1 key2 nsmutabledictionary (dict_n) keyn keyn nsmutabledictionary (dict_n) nsmutablearray (array_n) nsmutabledictionary (dict_n) keyn keyn nsmutabledictionary (dict_n) keyn keyn
if want change value of key1, there simplier way than...
getting dict1
getting dict2
getting array
getting dict3
converting dict3 mutable dictionary
setting key1
converting array mutable array
setting dict3 array
converting dict2 mutable dictionary
setting array dict2
converting dict1 mutable dictionary
setting dict2 dict1
doing each value have change real headache, , code consuming.
you can't send message object unless have pointer object, in basic sense answer question no, there's no other way.
however, 1 presumes data structure have represents sort of data model. such, should contained in sort of model class understands parts, , class should 1 needs understand how data stored. model class should offer higher-level interface data. dict3 represents 1 particular vehicle in fleet, , keys things "vehicletag", "registrationdate", "purchasedate", etc. maybe dictionaries @ dict2 level fleets in different regions, , dict2 represents northeast fleet. vehiclepool class, model class stores data, might offer methods like:
-registrationdateforvehicle:(int)vehicleindex infleet:(nsstring*)fleetkey; -setregistrationdate:(nsdate*)regdate forvehicle:(int)vehicleindex infleet:(nsstring*)fleetkey;
i'm not sure i'd want api -- i'd prefer list of vehicles given fleet , operate on simpler accessors, seem want avoid several levels of accessors. point here shouldn't writing ton of code operations need; should write methods know how access data , call those.
Comments
Post a Comment