This is for a legacy app in my org that was previously running is showing a compile warning and I'm not having any luck debugging it. (I'm not much of an Obj-C dev).
Function is:
static void newDrawTextInRect(UILabel *self, SEL _cmd, CGRect rect)
{
if (![self.text cxa_doesWrapInvisibleIdentifiers] ||
!titleSettingsPairs[self.text]){
origDrawTextInRect(self, @selector(drawTextInRect:), rect);
return;
}
UIImage *img = [titleSettingsPairs[self.text] image];
CGSize size = img.size;
CGPoint point = CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds));
point.x = ceilf(point.x - size.width/2);
point.y = ceilf(point.y - size.height/2);
BOOL drawsShadow = ![titleSettingsPairs[self.text] shadowDisabled];
CGContextRef context;
if (drawsShadow){
context = UIGraphicsGetCurrentContext();
CGContextSaveGState(context);
CGContextSetShadowWithColor(context, CGSizeMake(0, -1), 0, [[UIColor blackColor] colorWithAlphaComponent:1./3.].CGColor);
}
[img drawAtPoint:point];
if (drawsShadow)
CGContextRestoreGState(context);
}
and the line throwing the error is: UIImage *img = [titleSettingsPairs[self.text] image];
Edit: Adding context around titleSettingsPairs
static NSMutableDictionary *titleSettingsPairs;
&&
+ (void)load
{
static dispatch_once_t once;
dispatch_once(&once, ^{
titleSettingsPairs = [NSMutableDictionary dictionary];
});
}
&&
+ (void)dealloc
{
titleSettingsPairs = nil;
}
&&
- (void)cxa_setSettings:(CXAMenuItemSettings *)settings
{
if (!self.title)
@throw [NSException exceptionWithName:@"UIMenuItem+CXAImageSupport" reason:@"title can't be nil. Assign your item a title before assigning settings." userInfo:nil];
if (![self.title cxa_doesWrapInvisibleIdentifiers])
self.title = [self.title cxa_stringByWrappingInvisibleIdentifiers];
titleSettingsPairs[self.title] = settings;
}
EDIT: turns out the crash wasn't caused by this issue.