Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I store a UIImage in an NSDictionary?

How can I store a UIImage in an NSDictionary?

like image 712
RexOnRoids Avatar asked Feb 02 '10 17:02

RexOnRoids


People also ask

Does NSDictionary retain objects?

An NSDictionary will retain it's objects, and copy it's keys.

How do you add a UIImage in Objective C?

UIImage *img = [UIImage imageNamed:@"anyImageName"];

What is the difference between a UIImage and a UIImageView?

UIImage contains the data for an image. UIImageView is a custom view meant to display the UIImage .

What is the difference between NSMapTable vs NSDictionary?

NSDictionary / NSMutableDictionary copies keys, and holds strong references to values. NSMapTable is mutable, without an immutable counterpart. NSMapTable can hold keys and values with weak references, in such a way that entries are removed when either the key or value is deallocated.


1 Answers

Yes you can:

NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithCapacity:1];
UIImage *img = ...;
[dict setObject:img forKey:@"aKeyForYourImage"];

UIImage *imgAgain = [dict objectForKey:@"aKeyForYourImage"];
like image 82
Felix Lamouroux Avatar answered Oct 21 '22 23:10

Felix Lamouroux