ios - Iam adding the array in to the dictionary then remove the all objects from array -
iam adding array in dictionary remove objects array. when print dictionary shows empty.means array data present in dictionary removing.
if ([[[array objectatindex:0]objectatindex:i] isequaltostring:[filteredary objectatindex:j]]) { [menuary addobject:[array1 objectatindex:i]]; } [tempdict setvalue:menuary forkey:[filteredary objectatindex:j]]; [menuary removeallobjects];
why tempdict shows empty?
the array you're adding dictionary same object 1 you're removing objects from. adding dictionary not create new object, adds reference same object.
if want separate them, should add copy dictionary, so:
nsmutablearray *copiedarray = [[menuary mutablecopy] autorelease]; [tempdict setobject:copiedarray forkey:[filteredary objectatindex:j]]; //...
if use arc, can leave out autorelease
.
Comments
Post a Comment