hwaxxer
hwaxxer

Reputation: 3383

Cocoa Touch - How to cache a CGImageRef or UIImage (not using imageNamed:)?

I have a lot of images in my app so I decided to do some loading in a background thread, and since UIKit isn't thread-safe, I filled arrays with CGImageRefs. However, they are not cached and I need to be able to access them fast so my question is:

How to cache CGImageRef, or cache the UIImage derived from it later on in the main thread?

Upvotes: 2

Views: 1219

Answers (1)

corprew
corprew

Reputation: 2001

The UIImageView+Cached code found here implements a simple cache of UIImages combined with background loading in a thread.

I use this in my own projects. It works well. I recommend it. It should be easily adaptable to do what you want and a quick look says that pulling out the caching bits should be easy.

Upvotes: 3

Related Questions