From d4261661fe885b2cd704dfbe9be59a605de39bf0 Mon Sep 17 00:00:00 2001 From: tisfeng Date: Sat, 16 Dec 2023 09:59:48 +0800 Subject: [PATCH] fix: phonetic may be NSNull, [NSNull length] cause crash --- .../ViewController/View/WordResultView/EZWordResultView.m | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Easydict/Feature/ViewController/View/WordResultView/EZWordResultView.m b/Easydict/Feature/ViewController/View/WordResultView/EZWordResultView.m index f35589ac5..b04e1ab86 100644 --- a/Easydict/Feature/ViewController/View/WordResultView/EZWordResultView.m +++ b/Easydict/Feature/ViewController/View/WordResultView/EZWordResultView.m @@ -317,15 +317,17 @@ - (void)refreshWithResult:(EZQueryResult *)result { // 部分没有音标文本 EZLabel *phoneticLabel = nil; - if (obj.value.length) { + + // Fix: SIGABRT: -[NSNull length]: unrecognized selector sent to instance 0x7ff85c514b40 + NSString *phonetic = obj.value; + if ([phonetic isKindOfClass:NSString.class] && phonetic.length) { phoneticLabel = [[EZLabel alloc] init]; [self addSubview:phoneticLabel]; phoneticLabel.textContainer.lineFragmentPadding = 0; phoneticLabel.font = [NSFont systemFontOfSize:textFont.pointSize]; // ???: WTF, why Baidu phonetic contain '\n', e.g. ceil "siːl\n" - NSString *phonetic = [obj.value trim]; - phoneticLabel.text = [NSString stringWithFormat:@"/ %@ /", phonetic]; + phoneticLabel.text = [NSString stringWithFormat:@"/ %@ /", phonetic.trim]; [phoneticLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(phoneticTagLabel.mas_right).offset(kHorizontalMargin_8); make.centerY.equalTo(phoneticTagLabel);