title: How to loop through an array of objects in swift
body: <p>I'm trying to access the url of an object stored in an array, but I'm getting errors no matters what methods I'm using.</p>
  
  <pre><code>let userPhotos = currentUser?.photos
  
      for var i = 0; i &lt; userPhotos!.count ; ++i {
          let url = userPhotos[i].url
      }
  </code></pre>
  
  <p>Here I get </p>
  
  <blockquote>
    <p>Could not find member 'url'</p>
  </blockquote>
  
  <p>and with a foreach: </p>
  
  <pre><code>for photo in userPhotos {
  
          Utils.getImageAsync(photo.url , completion: { (img: UIImage?) -&gt; () in
  
          })
      }
  </code></pre>
  
  <p>I get: </p>
  
  <blockquote>
    <p>'[ModelAttachment]?' does not have a member named 'Generator'</p>
  </blockquote>
  
  <p>My array is <code>var photos: Array&lt;ModelAttachment&gt;?</code> and my ModelAttachment looks like this: </p>
  
  <pre><code>class ModelAttachment :Model {
  var id: String?
  var url: String?
  var thumb: String?
  }
  </code></pre>
  
  <p>Any pointers to what I'm doing wrong would be great :)</p>