我收到的输入 aNSAttributedString
可能包含附加为 的图像NSTextAttachment
。我需要检查是否真的附加了这样的图像,在这种情况下,将其删除。我一直在寻找相关的帖子,但没有成功,我该怎么做?
编辑:我正在尝试这个:
let mutableAttrStr = NSMutableAttributedString(attributedString: textView.attributedText)
textView.attributedText.enumerateAttribute(NSAttachmentAttributeName, in: NSMakeRange(0, textView.attributedText.length), options: NSAttributedString.EnumerationOptions(rawValue: 0)) { (value, range, stop) in
if (value as? NSTextAttachment) != nil {
mutableAttrStr.replaceCharacters(in: range, with: NSAttributedString(string: ""))
}
}
如果textView.attributedText
包含多个附件(我\u{ef}
在其中看到几个string
),我希望枚举if (value as? NSTextAttachment) != nil
多次匹配条件,但该代码块只执行一次。
如何删除所有附件?