Demo crashes on iOS 6
Closed this issue · 2 comments
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'NSConcreteMutableAttributedString addAttribute:value:range:: nil value' as - [ASValuePopUpView setTextColor:]
and - [ASValuePopUpView setFont:]
do not handle nil value.
- (void)setFont:(UIFont *)font
{
[_attributedString addAttribute:NSFontAttributeName
value:font
range:NSMakeRange(0, [_attributedString length])];
}
==>
- (void)setFont:(UIFont *)font
{
if (nil != font)
{
[_attributedString addAttribute:NSFontAttributeName
value:font
range:NSMakeRange(0, [_attributedString length])];
}
else
{
// Or use a default font settings ???
[_attributedString removeAttribute:NSFontAttributeName range:NSMakeRange(0, [_attributedString length])];
}
}
Thanks for raising the issue. The problem is caused by the use of the font Menlo-Bold in the demo app. Menlo-Bold isn't available on iOS6 so [UIFont fontWithName:@"Menlo-Bold" size:22]
returns nil.
I've adjusted the demo app to use a font which is available on iOS6. Instead of handling a nil value I've decided to explicitly assert that the font can not be nil in - (void)setFont:(UIFont *)font
.
NSAssert(font, @"font can not be nil, it must be a valid UIFont");
I think there's a danger of causing more confusion by using a default font when receiving a nil argument. For example if someone misspells the name of a font in UIFont fontWithName:
they will get the default font, instead of the one they were expecting. If an exception is raised the misspelling will be much easier to discover.