title: NSArray element failed to match the Swift Array Element type
body: <p>I have a Core Data object (Order) which has a method to return an array of another Core Data object (OrderWaypoint).</p>
  
  <pre><code>func getOrderedWaypoints() -&gt; [OrderWaypoint] {
      let nameDescriptor = NSSortDescriptor(key: "stop_number", ascending: true)
      let sorted: [OrderWaypoint] = self.waypoints.sortedArrayUsingDescriptors([nameDescriptor]) as [OrderWaypoint]
      return sorted
  }
  </code></pre>
  
  <p>Everything works as expected in the main target when using the following loop</p>
  
  <pre><code>for waypoint in order.getOrderedWaypoints() {
     // do something
  }
  </code></pre>
  
  <p>But when I try the exact same thing in my test target </p>
  
  <blockquote>
    <p>fatal error: NSArray element failed to match the Swift Array Element
    type</p>
  </blockquote>
  
  <p>I've tried casting the values but can't seem to get it to work. Any ideas why it works in the main target but not the test target?</p>
  
  <p>EDIT</p>
  
  <p>Well breaking it down further, the issue is specifically happening when I try to get an item out of the array.</p>
  
  <pre><code>var orderedList: [OrderWaypoint] = order.getOrderedWaypoints()
  
  for var i = 0; i &lt; orderedList.count; i++ {
     var waypoint = orderedList[i]
     // do something
  }
  </code></pre>