Question: I am trying to delete data from input field, but it's not deleting. 

```js
var myApp = angular.module('myApp',[]);

myApp.controller('MyCtrl', function MyCtrl($scope) {
    $scope.items = [
        {
            name: 'item 1',
            id: '4'
        },
        {
            name: 'item 2',
            id: '3'
        },
        {
            name: 'item 3',
            id: '2'
        },
        {
            name: 'item 4',
            id: '1'
        }
    ];

    $scope.delete = function (item) {
        $scope.items.splice($scope.items.indexOf(item), 1);
    }
});
```

```html
<div ng-controller="MyCtrl">
    <div ng-repeat="item in items | orderBy: 'id'" ng-click="delete(item)">
        <span>
            Hello, {{item.name}}!
        </span>
    </div>
    <input type="text" ng-model="items" />
</div>
<script src="https://code.angularjs.org/1.4.0/angular.js"></script>
```

Here is the [JSFIDDLE](http://jsfiddle.net/oymo9g2f/30/). 

```
$scope.delete = function (item) {
        $scope.items.splice($scope.items.indexOf(item), 1);
    }

```

Answer: 
It's OK to load image on the background, but it's not OK to perform UI updates on background thread. That's why the function must contain two threads.

```
func setupImageViewWithURL(url: URL) {
    var image: UIImage? = nil

    DispatchQueue.global().async { 
        do {
            try image = UIImage(data: Data(contentsOf: url))!
        } catch {
            print("Failed")
        }
        DispatchQueue.main.async(execute: {
            if image != nil {
                image = self.imageWithImage(sourceImage: image!, scaledToWidth: UIScreen.main.bounds.size.width)
                self.imageImageView.image = image
                self.imageImageView.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.size.width, height: (image?.size.height)!)
            }
        })
    }
}

```
Swift 4.0

> 
> 
> ```
> func setupImageViewWithURL(url: URL) {
> 
>     var image: UIImage? = nil
>     DispatchQueue.global(qos: .background).async {
>         do {
>             try image = UIImage(data: Data(contentsOf: url))!
>         } catch {
>             print("Failed")
>         }
>         DispatchQueue.main.async {
>             if image != nil {
>                 image = self.imageWithImage(sourceImage: image!, scaledToWidth: UIScreen.main.bounds.size.width)
>                 self.imageImageView.image = image
>                 self.imageImageView.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.size.width, height: (image?.size.height)!)
>             }
>         }
>     }
> }
> 
> ```
> 
>