How can I store a UIImage in an NSDictionary?
An NSDictionary will retain it's objects, and copy it's keys.
UIImage *img = [UIImage imageNamed:@"anyImageName"];
UIImage contains the data for an image. UIImageView is a custom view meant to display the UIImage .
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.
Yes you can:
NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithCapacity:1];
UIImage *img = ...;
[dict setObject:img forKey:@"aKeyForYourImage"];
UIImage *imgAgain = [dict objectForKey:@"aKeyForYourImage"];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With