0

I have an array of objects. I try to pass an object from the array to another controller and update it there.

let items: [XX] = [XX1, XX2]

The following line doesn't give a reference to that object. instead it is obviously copying it!

var item = items[0]

The following line fails to update the object in the array:

item.seen = true

Any ideas?

hasan
  • 23,815
  • 10
  • 63
  • 101
  • Can you please mention the reason of the downvote? – hasan Jul 30 '18 at 13:07
  • `this has nothing to do with arrays`. Do you mean that the OP should know where is his problem before he asks the question? isn't that why he is asking in the first place? which may be also the case for others who also thinks that the array was the problem. and thats maybe why I didn't find the answer searching using the keywords that I thought caused the problem. which also maybe used by others. – hasan Aug 01 '18 at 10:06
  • `Also show real code, not snippets, as your testing procedure might be faulty` If the code added serves the purpose and its not faulty how would you know its 'maybe faulty`? – hasan Aug 01 '18 at 10:09
  • I am not sure about the rule here. but I think that a question that uses different keywords and has same answer as another question should stay. and it shouldn't be treated as a duplicate. – hasan Aug 01 '18 at 10:11

1 Answers1

3

You need to make it an array of class type , not struct type , then manipulating will be reflected to the original array

Shehata Gamal
  • 98,760
  • 8
  • 65
  • 87