Объект не может быть нулевым (ключ: NSFont) в NSMutableAttributedString в UILabel на iOS 17–18.IOS

Программируем под IOS
Ответить Пред. темаСлед. тема
Anonymous
 Объект не может быть нулевым (ключ: NSFont) в NSMutableAttributedString в UILabel на iOS 17–18.

Сообщение Anonymous »

Я столкнулся с ошибкой выполнения в своем приложении iOS при попытке установить для NSAttributedString значение UILabel. Сообщение о сбое в Firebase Crashlytics:

Код: Выделить всё

*** -[__NSDictionaryM setObject:forKey:]: object cannot be nil (key: NSFont)
Мой фрагмент кода

Код: Выделить всё

public final class HotelListPresentation {

public init() {
prepareRating()
}

private func prepareRating() {
// Rating Status
if let commentCount = hotel.commentCount, let ratingtext = hotel.averageScoreText {
let commentText = (commentCount >= 3 ? " (\(commentCount) \(TextKey.hotelComment.localized))" : "")
let boldFont = UIFont.systemFont(ofSize: 15, weight: .bold)
let regularFont = UIFont.systemFont(ofSize: 12)
let titleColor = UIColor.blue
let mutableAttributedString = NSMutableAttributedString()
mutableAttributedString.append(NSAttributedString(string: ratingtext, attributes: [.font: boldFont, .foregroundColor: titleColor]))
mutableAttributedString.append(NSAttributedString(string: commentText, attributes: [.font: regularFont, .foregroundColor: titleColor]))
self.ratingStatusAttributed = mutableAttributedString
}
}
}

public final class HotelListTableViewCell: UITableViewCell {

@IBOutlet private var starsComponent: HotelStarsComponent!
@IBOutlet private var ratingStackView: UIStackView!
@IBOutlet private var ratingLabel: Label!
@IBOutlet private var ratingBackgroundView: UIView!
@IBOutlet private var ratingStatusLabel: Label!

func configure(with data: HotelListPresentation) {
let rating = data.averageScore ?? 0
ratingLabel.text = rating.ratingDescription
ratingBackgroundView.tintColor = data.averageScoreColor
ratingStackView.isHidden = rating == 0 ? true : false
ratingStatusLabel.attributedText = data.ratingStatusAttributed // Crash line
}
}
Это точный код, несвязанные разделы удалены для ясности. Хотя я не могу поделиться всей кодовой базой из-за ограничений, эта часть точно отражает реальный процесс работы с рейтингомStatusLabel.
Вот журнал крашлитика,

Код: Выделить всё

Fatal Exception: NSInvalidArgumentException
*** -[__NSDictionaryM setObject:forKey:]: object cannot be nil (key: NSFont)
0
CoreFoundation
__exceptionPreprocess
1
libobjc.A.dylib
objc_exception_throw
2
CoreFoundation
-[__NSDictionaryM setObject:forKey:]
3
CoreFoundation
-[NSMutableDictionary addEntriesFromDictionary:]
4
Foundation
-[NSMutableAttributedString addAttributes:range:]
5
Foundation
-[NSAttributedString enumerateAttributesInRange:options:usingBlock:]
6
UIKitCore
-[NSAttributedString _ui_synthesizeAttributedSubstringFromRange:usingDefaultAttributes:]
7
UIKitCore
-[UILabel _synthesizedAttributedTextForContent:]
8
UIKitCore
-[UILabel _synthesizedAttributedText]
9
UIKitCore
-[UILabel _textRectForBounds:limitedToNumberOfLines:includingShadow:]
10
UIKitCore
-[UILabel _intrinsicSizeWithinSize:]
11
UIKitCore
-[UILabel _ensureBaselineMetricsReturningBounds]
12
UIKitCore
-[UILabel _baselineOffsetFromBottom]
13
UIKitCore
-[UILabel _invalidateBaselineConstraints]
14
UIKitCore
-[UILabel _setContent:adjustingFontForAccessibilityTraits:adjustingFontForTypesettingLanguage:adjustingFontForTypesettingLanguageAwareLineHeightRatio:checkingForDifferences:]
15
UIKitCore
-[UILabel _setContent:]
16
UIKitCore
-[UILabel setAttributedText:]
17
obilet
HotelListTableViewCell.swift - Line 130
specialized HotelListTableViewCell.configure(with:imageSliderDataSource:) + 130
18
HotelApp
closure #1 in HotelListView.tableDataSource.getter
Кто-нибудь сталкивался с этой проблемой? Сбой задокументирован в Firebase Crashlytics. Самое смешное, что он происходит не всегда и появляется только в более поздних версиях iOS17, особенно 17.6.1 и 18. Будем очень признательны за любую помощь!

Подробнее здесь: https://stackoverflow.com/questions/790 ... abel-on-io
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «IOS»