nsarray - copy custom array without pointing old array in iOS ARC -


I would like to know how can I make a deep copy of the custom array without pointing to the old array. I have examined almost all stack overflow queries but no solution was found. Please help copy the array without pointing to my old array so that my new array operation does not affect (add, remove) the original / old array.

This is my main manifestation manifesto.

  @ Property (non-dynamic, strong) NSArray * secArray;   

Add a custom object to the array

  NSMutableArray * secDataArray = [NSMutableArray array]; [SetRequest.SetMembersEnumerateObjectsUsingBlock: ^ (SetMember * subscriber, NSUInteger idx, block *) {SecData * secData = [secDataArray lastObject]; (Sec SecData.open = Yes; [Second Data Arrayed Object: Second Data]; } And {{secData.lines addObject: member]; }}];  
  New array in deep copy of custom array  
  NSArray * newSecarray = [[NSMutableArray alloc] initWithArray: secArray copyItems: Yes];   

But extracting data from the new array also removes data from the old array.

  SecData * dataoldarraydata = [self .secArray objectAtIndex: 0]; Cetadadata * DatanoverRadata = [Nayashera ObjectTitx: 0]; [DataVareDrata. Deletes RemovesOustubs]; NSLog (@ "oldadadata =% d", [second line, line count]); // output = 33 (this should be 34 because I do not want to delete the data from the original array) NSLog (@ "newereredata =% d", [nsarea line count]); // Output = 33   

// Here is my custom Sequeta class.

// secData.h file

  @ interface secondary data: NSObject @property (nonatomic, strong) NSMutableArray * line; @property (non-standard, strong) NSString * secTitle; @property (non-standard, strong) NSString * secIndexTitle; @property (nonatamic, assigned) Open the BOOL; + (Id) secDataWithTitle: (NSString *) inTitle lines: (NSArray *) in inline; + (ID) Second Data with Lines: (NSARRA *) Inline; + (ID) copy; @end   

// secData.m file

  #import "SecData.h" @ implementation SecData @ synthesis lines; + (ID) Second Wothline: (NSERRE *) Inline {Returns [Self-Separate With Title: Zero Line: Inline]; } + (ID) Sacredite Little: (NSString *) In-Tight Lines: (NSERRE *) Inline {Secend * Sec = (Sectata *) [[SILOL] IIT]; [Second set: acctital: intial]; NSMutableArray * mutableCopyArray = [[NSMutableArray alloc] initWithArray: inline]; [Second setline: mutable copy array]; Back Refresh; } - (NSMutableArray *) lines {if (lines!) {Self lines = [NSMUtABE array array]; } Return line; } - (Zero) Setline: (NSMUTABELARRA *) AERE {NSMUTABELRA * NewAre = AEERE; If (! [AARRE KindoffClass: [NSMUTABELARAA class]]) Newer = [NSMUTABARAARRAREERETHRA: AARAAR]; Lines = new arrays; } - (Id) Copy with Zone: (NSZEN *) Area {ID seccopy = [[[Self class] alloc] init]; If (cesopi) {NSMutableArray * temp = [[NSMutableArray alloc] initWithArray: self.lines copyItems: yes]; [CESCP set SECL: self Sectite]; [Cescopi Setline: Self. Lines]; } Return seccopy; } @end    

If you need a really deep copy then there is also a way That you can archive the archive and then store the archive. You must apply / store the protocol to store it in your classes. This is not an effective way but it provides the right deep copy i.e. Your arrays will be completely different.

Use this code to copy:

  NSArray * newSecArray = [NSKeyedUnarchiver unarchiveObjectWithData: [NSKeyedArchiver archivedDataWithRootObject: secArray]];   

You can also see about shallow and deep imitation. Apple also tells this method for deep copying in its docs.

Here is a link to encode / decode objects.

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -