Graphics Programs Reference
In-Depth Information
+ (BNRImageStore *)sharedStore
{
static BNRImageStore *sharedStore = nil;
if (!sharedStore) {
// Create the singleton
sharedStore = [[super allocWithZone:NULL] init];
}
return sharedStore;
}
- (id)init
{
self = [super init];
if (self) {
dictionary = [[NSMutableDictionary alloc] init];
}
return self;
}
Then, implement the other three methods declared in the header file.
- (void)setImage:(UIImage *)i forKey:(NSString *)s
{
[dictionary setObject:i forKey:s];
}
- (UIImage *)imageForKey:(NSString *)s
{
return [dictionary objectForKey:s];
}
- (void)deleteImageForKey:(NSString *)s
{
if (!s)
return;
[dictionary removeObjectForKey:s];
}
NSDictionary
Notice that the dictionary is an instance of NSMutableDictionary . A dictionary
is a lot like an array: it is a collection object and it has an immutable ( NSDictionary )
and mutable version ( NSMutableDictionary ). However, dictionaries and arrays dif-
fer in how they store their objects. An array is an ordered list of pointers to objects that is
accessed by an index. When you have an array, you can ask it for the object at the n th in-
dex:
// Put some object at the beginning of an array
[someArray insertObject:someObject atIndex:0];
// Get that same object out
Search WWH ::




Custom Search