deep copy

Discussion in 'iPhone/iPad Programming' started by rahul29tech, Apr 25, 2012.

  1. macrumors member

    Joined:
    Dec 22, 2011
    #1
    how to do deep copy of an NSMutableArray of images into an another NSMutableArray????

    plz sugest me plzzzzzzzz:(
     
  2. macrumors 68000

    Kyotoma

    Joined:
    Nov 11, 2010
    Location:
    Carnegie and Ontario
    #2
    What is this referring to? Can you go into more details as to what you are talking about?

    In the future, try and use proper grammar and spelling. Posters here will understand your problem better if you explain it better than what you have originally posted. Oh, and you'll most likely get a better response out of them if you're nice and unassuming that we all here know what it is you are talking about. :)
     
  3. macrumors regular

    Joined:
    Mar 20, 2006
    #3
    I think you will need to call the copy method on each element in the array otherwise only the addresses of the objects will be copied.
     
  4. macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #4
    If it's custom objects in the array, you need to add NSCopying protocol to your custom Objects.
    Otherwise, you can do a full copy of the entire array like
    Code:
    NSMutableArray *array2 = [otherArray copy];
    
    But your question is rather vague.. maybe try hinting what you want to do exactly.
     
  5. thread starter macrumors member

    Joined:
    Dec 22, 2011
    #5
    Sir this is normal copy method which you suggest me, but i want something like that when after copy of 1array into another ,so remove of element from this one of the array ,not effects element of copied array's element.....

    so i want deepcopy of array so how can i achieve this
     
  6. macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #6
    Errr, do a remove object at index at array 1, and add to 2nd.. What you are saying doesn't really make sence in my honest opinion.
     
  7. macrumors 68040

    Joined:
    Apr 22, 2005
    #7
    Code:
    NSMutableArray *copiedArray = [[NSMutableArray alloc] initWithArray:originalArray copyItems:YES];
    "Deep copy" is a standard computer science term for a copy of an object that also copies any objects that the copied object refers to. This is opposed to a "shallow copy" which just copies the object and points any references to the same objects that the copied objects refers to.
     

Share This Page