Question: I have a function that changes an image that takes a long time to finish (on the order of 10s). This image changes each iteration, and I would like to display it each time.

I would like

```
self.imageView.image = [ /* function that changes image */ ];

```

but I accept why that won't work.

I've also tried the following:

```
 self.imageView.animationImages = [NSArray arrayWithObjects:[self.brain newImage],
                                                            [self.brain newImage],
                                                             nil];

```

but it takes a long time before the animation starts.

How do I make an animation that updates each time the function is called?

Note: `[self.brain newImage]` is a valid function that returns a UIImage, and changes each time. I didn't include the actual code since it's complex and not the problem.

Answer: 
You may try this code to set the animation on your image array

```
if(imageArray.count>0)
{
    self.imageView.animationImages= imageArray;
    self.imageView.animationDuration = 1/20;
    self.imageView.animationRepeatCount =1;
    [self.imageView startAnimating];
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1.0];
    [UIView commitAnimations];
}

```

I have set the animation time 1/20 as per FPS you can set yours and also animation repeat count to 0 for repeat forever
Consider adding a block parameter to your `-newImage` method:

```
- (void)newImageWithSuccessBlock:(void (^)(UIImage *newImage))successBlock
{
    // generate the image on a background thread
    UIImage *brainImage = ...

    // if successful and the completion block isn't nil, run it
    if (successBlock) {
        // NB: if you do use a background queue,
        // remember to dispatch the completion block to the main queue (not shown)
        successBlock(brainImage)  
    }

}

```

Then, on generating new images from your view controller you can update your image view:

```
[self.brain newImageWithSuccessBlock:^(UIImage *newImage) {

    NSMutableArray *mutableImageArray;
    if (self.imageView.animationImages) {
        mutableImageArray = [self.imageView.animationImages mutableCopy];
    } else {
        mutableImageArray = [NSMutableArray array];
    }

    [mutableImageArray addObject:newImage];

    self.imageView.animationImages = [NSArray arrayWithArray:mutableImageArray];

}];

```