title: How to not get different memory addresses for elements in a Realm List?
body: <p>If I iterate over an array in Swift with:</p>
  
  <pre><code>for element in array {
      ...
  }
  </code></pre>
  
  <p>and place a breakpoint inside the for statement and look at the address of the object stored as element, than I get a different address than if I let the debugger run the expression:</p>
  
  <pre><code>array.first
  </code></pre>
  
  <p>There is only one element in the array. So, why do I not get the same address?
  Here is a screenshot of the debugger in action:</p>
  
  <p><a href="https://i.stack.imgur.com/OH8QI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OH8QI.png" alt="enter image description here"></a></p>
  
  <p>I am iterating over the attachments of a mail. When I debugged, the mail only had one attachment. The debugger also stopped in the first iteration. In my two expressions you can see, that attachment has another address than attachments.first</p>
  
  <p>I don't know if that helps or matters, but Message is an object managed by Realm and so is Attachment. message.attachments is of type List. </p>
  
  <h1><strong>EDIT:</strong></h1>
  
  <p>I investigated further and it gets more weird.
  I have a class Message, which is a Realm Object and has a property List of Attachments, which are also Realm Objects.</p>
  
  <pre><code>import RealmSwift
  class Message: Object {
      let attachments = List&lt;Attachment&gt;()
      ...
  }
  class Attachment: Object {
      ...
  }
  </code></pre>
  
  <p>I debugged the point where attachments are appended. After all attachments are processed, I can ask for the first element and always get the same instance with the same memory address. Behavior is like I expect it.</p>
  
  <p>When the message in later usage is passed around views, I can see, that the address of the message is the same in every view holding a reference. But if I then ask for the first attachment, I always get a different address. I even get different addresses when not moving in debug mode and just running the same expression multiple times:</p>
  
  <p><a href="https://i.stack.imgur.com/PG0Tz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/PG0Tz.png" alt="enter image description here"></a></p>
  
  <p>This is not like I expect it.</p>