Я бы сказал, что ошибка не в Swift, а в Cocoa, который написан на Objective-C и ничего не знает о перечислениях Swift. Поэтому это словарное значение, как вы сами сказали, является целым числом, а не перечислением Swift. Поэтому, чтобы поговорить с Какао, мы должны «пересечь мост», взяв необработанное значение enum.

учаю сбои во время выполнения всякий раз, когда я пытаюсь установить подчеркивание или зачеркнутые атрибуты для атрибутного текста UITextView. Другие свойства, такие как шрифт и цвет фона, не имеют проблем. Вот фрагмент кода. Все, что у меня есть, это тестовый проект с одним UITextView. Я на iOS 11.

class ViewController: UIViewController {

    @IBOutlet weak var myTextView: UITextView!

    var myMutableString = NSMutableAttributedString(string: "")

    override func viewDidLoad() {
        super.viewDidLoad()

        let string = "The cow jumped over the moon" as NSString
        myMutableString = NSMutableAttributedString(string: string as String)

        let underlineAttribute = [NSAttributedStringKey.underlineStyle: NSUnderlineStyle.styleSingle]

        myMutableString.addAttributes(underlineAttribute, range: string.range(of: "cow"))

        myTextView.attributedText = myMutableString
    }
}

Это приводит к исчезновению текста и печати некоторых ошибок:

2017-11-05 19:43:34.708830-0800 UITextView_Test[11771:907014]
-[_SwiftValue _getValue:forType:]: unrecognized selector sent to instance 0x60c00004eb50 2017-11-05 19:43:34.709351-0800 UITextView_Test[11771:907014] <NSATSTypesetter: 0x60800016be80>: Exception -[_SwiftValue _getValue:forType:]: unrecognized selector sent to instance 0x60c00004eb50 raised during typesetting layout manager <NSLayoutManager: 0x6080001fe400>
    1 containers, text backing has 28 characters
    Currently holding 28 glyphs.
    Glyph tree contents:  28 characters, 28 glyphs, 1 nodes, 64 node bytes, 64 storage bytes, 128 total bytes, 4.57 bytes per character,
4.57 bytes per glyph
    Layout tree contents:  28 characters, 28 glyphs, 0 laid glyphs, 0 laid line fragments, 1 nodes, 64 node bytes, 0 storage bytes, 64 total bytes, 2.29 bytes per character, 2.29 bytes per glyph, 0.00 laid glyphs per laid line fragment, 0.00 bytes per laid line fragment , glyph range {0 28}. Ignoring... 2017-11-05 19:43:34.709827-0800 UITextView_Test[11771:907014] -[_SwiftValue _getValue:forType:]: unrecognized selector sent to instance 0x60c00004eb50 2017-11-05 19:43:34.710014-0800 UITextView_Test[11771:907014] <NSATSTypesetter: 0x60800016be80>: Exception -[_SwiftValue _getValue:forType:]: unrecognized selector sent to instance 0x60c00004eb50 raised during typesetting layout manager <NSLayoutManager: 0x6080001fe400>
    1 containers, text backing has 28 characters
    Currently holding 28 glyphs.
    Glyph tree contents:  28 characters, 28 glyphs, 1 nodes, 64 node bytes, 64 storage bytes, 128 total bytes, 4.57 bytes per character,
4.57 bytes per glyph
    Layout tree contents:  28 characters, 28 glyphs, 0 laid glyphs, 0 laid line fragments, 1 nodes, 64 node bytes, 0 storage bytes, 64 total bytes, 2.29 bytes per character, 2.29 bytes per glyph, 0.00 laid glyphs per laid line fragment, 0.00 bytes per laid line fragment , glyph range {0 28}. Ignoring...

Ответы на вопрос(1)

Ваш ответ на вопрос