objective c - NSDictionary getting changed when removing a object from NSMutableArray? -


i'm having 1 dictionary & array in remove object array means reflect in dictionary below code,

nsmutablearray * plandetailarr; nsdictionary *singleitemdict; - (void)viewdidload {     [super viewdidload];     plandetailarr=[[nsmutablearray alloc]init];     singleitemdict=[[nsdictionary alloc]init];} //parsing json response -(void)responsefun:(nsmutabledictionary *)response {             singleitemdict=response;         plandetailarr=response[@"plandetails_array"];          //removing 2 values array         [plandetailarr removelastobject];         [plandetailarr removeobjectatindex:0]; } 

in above code remove values in array only.when print array & dictionary after removing values reflects in dictionary me please..

note:as print response getting removed.

you need copy of dictionary. since pointing same object actual object's values change.

singleitemdict=[response copy]; plandetailarr=[response[@"plandetails_array"] mutablecopy]; 

this fix problem.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -