Skip to content

Commit

Permalink
Protecting against nil images
Browse files Browse the repository at this point in the history
  • Loading branch information
kgn committed Jun 2, 2012
1 parent 21bd19f commit b3f9938
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion UIImage+BBlock.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ + (NSCache *)drawingCache{
}

+ (UIImage *)imageForSize:(CGSize)size withDrawingBlock:(void(^)())drawingBlock{
if(size.width <= 0 || size.width <= 0){
return nil;
}

UIGraphicsBeginImageContextWithOptions(size, NO, 0.0f);
@autoreleasepool{
drawingBlock();
Expand All @@ -41,7 +45,9 @@ + (UIImage *)imageWithIdentifier:(NSString *)identifier forSize:(CGSize)size and
UIImage *image = [[[self class] drawingCache] objectForKey:identifier];
if(image == nil){
image = [[self class] imageForSize:size withDrawingBlock:drawingBlock];
[[[self class] drawingCache] setObject:image forKey:identifier];
if(image != nil){
[[[self class] drawingCache] setObject:image forKey:identifier];
}
}
return image;
}
Expand Down

0 comments on commit b3f9938

Please sign in to comment.