Reputation: 10139
So I have this NSMutableDictionary object:
pdata=[[NSMutableDictionary alloc] initWithObjectsAndKeys:
@"",@"pid",
@"",@"pname",
[[NSMutableArray alloc] initWithCapacity:1],@"ilist",
nil];
And then I copy this object into another object like this:
NSMutableDictionary *pdataCopy=[[NSMutableDictionary alloc] initWithDictionary:pdata copyItems:TRUE];
But once Ive done this, pdataCopy.ilist
is now an NSArray instead of NSMutableArray.
How can I copy a dictionary object whilst maintaining the mutability of the properies inside it?
Upvotes: 0
Views: 531
Reputation: 47739
You have three options:
copyItems:YES
mutableCopy
) as desired.copyWithZone
by producing a mutable copy of itself (and use objects of that class in your dictionary).Upvotes: 0
Reputation: 9101
Actually you can't. You can get a mutable array by
NSMutableArray *mutableArray = [pdataCopy.ilist mutableCopy]
Upvotes: 2