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
If the `animationImages` approach is fine with you, you can make it start faster by creating in advance the images:

```
//-- preload images (e.g., while the app is loading)
NSArray* images = [NSArray arrayWithObjects:[self.brain newImage],
                                                        [self.brain newImage],
                                                         nil];
//-- display animation
self.imageView.animationImages = images;

```

Keep in mind that the `animationImages` approach has limitations, mostly the fact that you need to create all of your images in advance -- and this could take up a lot of memory.

One alternative approach would be using a `CALayer` and a `NSTimer`: each time the times fires, you set the `layer.contents` to the next image. For more information about this approach, see [this](http://mysterycoconut.com/blog/2011/01/cag1/).

For more advanced approaches, you could resort to cocos2d or openGL, but this might be overkill.