Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Objective-C and Swift
  4. NSMutableArray copy problem

NSMutableArray copy problem

Scheduled Pinned Locked Moved Objective-C and Swift
helpdata-structures
6 Posts 3 Posters 37 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Le rner
    wrote on last edited by
    #1

    Hi all, i have two different NSMutableArray one is source array and other is backup array, on some action copy the source array value to backup array. than continue the changes in source array objects. but here the backup array objects value automatically changed as i changed in source array. please help me i don't want to change backup array object even i change in source array object. thanks in advance.

    L 1 Reply Last reply
    0
    • L Le rner

      Hi all, i have two different NSMutableArray one is source array and other is backup array, on some action copy the source array value to backup array. than continue the changes in source array objects. but here the backup array objects value automatically changed as i changed in source array. please help me i don't want to change backup array object even i change in source array object. thanks in advance.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      I do not know Objective-C or Swift, but your description sounds like you have copied the object references instead of the actual content.

      L 1 Reply Last reply
      0
      • L Lost User

        I do not know Objective-C or Swift, but your description sounds like you have copied the object references instead of the actual content.

        L Offline
        L Offline
        Le rner
        wrote on last edited by
        #3

        help me how can i correct this...

        L 1 Reply Last reply
        0
        • L Le rner

          help me how can i correct this...

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          As I stated in my previous message, "I do not know Objective-C or Swift". So you need to look at what your code is actually doing and why it is not doing deep copy operations. Hint: you could always try the documentation for whichever language you are using.

          G 1 Reply Last reply
          0
          • L Lost User

            As I stated in my previous message, "I do not know Objective-C or Swift". So you need to look at what your code is actually doing and why it is not doing deep copy operations. Hint: you could always try the documentation for whichever language you are using.

            G Offline
            G Offline
            gurdevs80
            wrote on last edited by
            #5

            You need to clone the contents of the source array. [copy] method of NSMutableArray makes a reference copy with new array variable hence your content in backup array gets updated when you update source array. Use

            NSMutableArray initWithArray

            to create a clone of source array but with new reference pointer to it. Hope it helps.

            L 1 Reply Last reply
            0
            • G gurdevs80

              You need to clone the contents of the source array. [copy] method of NSMutableArray makes a reference copy with new array variable hence your content in backup array gets updated when you update source array. Use

              NSMutableArray initWithArray

              to create a clone of source array but with new reference pointer to it. Hope it helps.

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              I don't think this message was meant for me.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups