Re: Using NSImages as keys to a dictionary
Re: Using NSImages as keys to a dictionary
- Subject: Re: Using NSImages as keys to a dictionary
- From: Andrew Bowman <email@hidden>
- Date: Fri, 12 May 2006 23:40:02 -0700
On May 12, 2006, at 11:24 PM, Lawrence Sanbourne wrote:
Hello,
My app needs a way of caching scaled images (thumbnails) so that they
aren't recreated each time. I first did this using an
NSMutableDictionary mapping from original image to scaled image.
However, this didn't work because apparently one original image wasn't
isEqual: to another.
I realized that I just wanted pointer equality. So I did this:
// originalIcon is an NSImage *
[cachedIcons objectForKey:[NSNumber numberWithInt:(int)originalIcon]];
It works beautifully. However, this code seems really weird to me. Is
there a better way?
Larry
Hey Larry,
You could always create a NSImage subclass which holds its own
singleton thumbnail. If the thumbnail is nil when you request it,
create it.
- Andrew Bowman
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden