nsdictionary - Mutable deep-copy of a NSMutableDictionary -


First of all I found something similar. But this does not solve my problem

I have it. A NSMutableDictionary as a template

  NSMutableDictionary * mutableDictionaryTemplate = [NSMutableDictionary dictionaryWithObjectsAndKeys: @ "obj1, @" key1 ", @" obj2, @ "key2", zero];   

Now I copy this dictionary, then change some parts and later.

  NSMutableArray * savedIterations = [NSMutableArray want to save in a new NSMutable array]; // Some loops that usually change objects i int = 0; (I & lt; 5) {NSMutableDictionary * copiedDictionary = [mutableDictionaryTemplate copy]; [CopiedDictionary set object: @ "obj3" for: @ "key3"]; [Saved change addObject: copiedDictionary]; I ++; }   

My problem is that it is now variable once I copy the NSMutableDictionary "mutableDictionaryTemplate". But I need to copy it because otherwise I will have the same NSMutableDictionary in my index of each of its NSMutableArray "savedIterations" (at least I think so). I also tried a temporary copy but changed the "mutableDictionaryTemplate" when I changed "copied". I think there is something wrong with what I have to copy and what is not and how to copy it correctly. It would be great if someone pointed me in the right direction.

You can try this:

  NSMutableDictionary * destinationDictionary = (NSMutableDictionary *) CFBridgingRelease (CFPropertyListCreateDeepCopy (kCFAllocatorDefault, (__bridge CFPropertyListRef) (sourceDictionary), kCFPropertyListMutableContainers));    

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -