Graphics Programs Reference
In-Depth Information
// If possible, get it from the dictionary
UIImage *result = [dictionary objectForKey:s];
if (!result) {
// Create UIImage object from file
result = [UIImage imageWithContentsOfFile:[self imagePathForKey:s]];
// If we found an image on the file system, place it into the cache
if (result)
[dictionary setObject:result forKey:s];
else
NSLog(@"Error: unable to find %@", [self imagePathForKey:s]);
}
return result;
}
When a BNRItem is removed from the store, its image should also be removed from the
filesystem. At the top of BNRItemStore.m , import the header for the
BNRImageStore and add the following code to removeItem: .
#import "BNRImageStore.h"
@implementation BNRItemStore
- (void)removeItem:(BNRItem *)p
{
NSString *key = [p imageKey];
[[BNRImageStore sharedStore] deleteImageForKey:key];
[allItems removeObjectIdenticalTo:p];
}
Build and run the application again. Take a photo for a item, exit the application, and then
kill it from the dock. Launch the application again. Selecting that same item will show all
its saved details - including the photo you just took.
Also, notice that the images were saved immediately after being taken, while the
BNRItem s were saved only when the application entered background. We saved the im-
ages right away because they are just too big to keep in memory for long.
Search WWH ::




Custom Search