title: Assign a new image to UIImageView with Swift
body: <p>I'm using Xcode 6 Beta 4, and I'm trying to retrieve a remote image and assign it to a UIImageView. I'm using an NSURLSession dataTask in order to make this asynchronous. Here is my code:</p>
  
  <pre><code>func dataTask(imageUrl: String, targetImage:UIImageView) {
  
      let nsURL = NSURL(string: imageUrl)
  
      let task = NSURLSession.sharedSession().dataTaskWithURL(nsURL) {
          (data, response, error) in
          if !error {
              NSLog("No Error!")                
              var image:UIImage = UIImage(data: data)
              targetImage.image = image
          }
          else {
              NSLog("Error!")
          }
      }
  
      task.resume()
  }
  </code></pre>
  
  <p>this is how i make the call:</p>
  
  <pre><code>        self.dataTask("http://bicicletaspony.com/img/spn/TeamA.png", targetImage: image)
  </code></pre>
  
  <p>And this is the error i get :(</p>
  
  <blockquote>
    <p>Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Modifications to the layout engine must not be performed from a background thread.'</p>
  </blockquote>
  
  <p>It's a very simple image assignment. Why does it crash that way?! any help will be much appreciated!</p>