Когда я добавляю несколько картинок в переменную типа NSAttributedString через NSTextAttachment по итогу в строке отображается последняя добавленная картинка во всех NSTextAttachment, как от этого избавиться может уже кто сталкивался с этой проблемой?
вот код
func parseString(_ text: String) -> NSAttributedString {
let fullString = NSMutableAttributedString(string: “”)
let imgAttachment = NSTextAttachment()
var substring: NSString?
let skipped = CharacterSet(charactersIn: "~")
let scanner = Scanner(string: text)
scanner.charactersToBeSkipped = skipped
while scanner.isAtEnd == false {
scanner.scanUpToCharacters(from: skipped, into: &substring)
if let str = substring {
if str.hasSuffix(".png") {
imgAttachment.image = UIImage(named: String(str))
let imageString = NSAttributedString(attachment: imgAttachment)
fullString.append(imageString)
} else {
fullString.append(NSAttributedString(string: String(str)))
}
}
}
return fullString
}
я так понимаю Swift ссылку на последний объект лепит во все вложения или я ошибаюсь?