Created
February 26, 2015 23:04
-
-
Save xtreme-daniel-crampton/f9792d8336297af613a0 to your computer and use it in GitHub Desktop.
+ [UIImage noNilImageNamed:]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// UIImage+NoNilImageNamed.m | |
// UARecord | |
// | |
// Created by DX131 on 2/26/15. | |
// Copyright (c) 2015 Under Armour. All rights reserved. | |
// | |
#import "UIImage+NoNilImageNamed.h" | |
#import <objc/runtime.h> | |
@implementation UIImage (NoNilImageNamed) | |
+ (void)load { | |
static dispatch_once_t onceToken; | |
dispatch_once(&onceToken, ^{ | |
method_exchangeImplementations(class_getClassMethod(self, @selector(imageNamed:)), class_getClassMethod(self, @selector(noNilImageNamed:))); | |
}); | |
} | |
#pragma mark - Method Swizzling | |
+ (instancetype)noNilImageNamed:(NSString *)imageName { | |
if (imageName && imageName.length) { | |
return [UIImage noNilImageNamed:imageName]; | |
} | |
NSString *sourceString = [[NSThread callStackSymbols] objectAtIndex:1]; | |
NSCharacterSet *separatorSet = [NSCharacterSet characterSetWithCharactersInString:@" -[]+?.,"]; | |
NSMutableArray *array = [NSMutableArray arrayWithArray:[sourceString componentsSeparatedByCharactersInSet:separatorSet]]; | |
[array removeObject:@""]; | |
UALog(@"Called [UIImage imageNamed:] with a nil image name from [%@ %@]", array[3], array[4]); | |
return nil; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment