

Introduction

SwapTest demonstrates how to load big images in the background and display/swap them during a drag operation with minimal lag.

When judging the smoothness of the UI keep in mind that there's a background thread working as hard as the CPU allows all the time, and that the images are 2048x2048.

The action happens in the SwapTestViewController.

This version uses a pretty crazy optimization: The CPU gets a bit overwhelmed when it receives the drag events in short intervals and has to set the layers contents to a new value in between. For that reason, I store the loaded UIImage in the temporaryImage, and apply both the change caused by the drag event and the new contents when the next drag event occurs. 
This improves UI-smoothness, but you can probably throw this optimization out if you're using smaller images, or don't have an active background thread all the time.

If you know any improvments, add a response to the corresponding Stack-Overflow question: http://stackoverflow.com/questions/5266272/non-lazy-image-loading-in-ios.


Thanks to Timmy and Kazuki Sakamoto for the help.
