Core data 在core数据中保存带有图像附件的NSMutableAtributed字符串
我声明了一个NSMutable属性字符串,并将不同的属性字符串附加到它。这些属性化字符串可能包含作为NSTextattachments的图像Core data 在core数据中保存带有图像附件的NSMutableAtributed字符串,core-data,swift3,nsmutableattributedstring,nstextattachment,Core Data,Swift3,Nsmutableattributedstring,Nstextattachment,我声明了一个NSMutable属性字符串,并将不同的属性字符串附加到它。这些属性化字符串可能包含作为NSTextattachments的图像 var historyText : NSMutableAttributedString = NSMutableAttributedString(string: "") let imageAttachment = NSTextAttachment() imageAttachment.image = UIImage(named: "some_image") i
var historyText : NSMutableAttributedString = NSMutableAttributedString(string: "")
let imageAttachment = NSTextAttachment()
imageAttachment.image = UIImage(named: "some_image")
imageAttachment.bounds = CGRect(x:0, y:-3.0, width: (imageAttachment.image?.size.width)!, height:(imageAttachment.image?.size.height)!)
let imageString = NSAttributedString(attachment: imageAttachment)
historyText.append(imageString)
然后,我将该属性文本保存在核心数据中。但是,当我从核心数据检索此属性文本时,imageAttachment.bounds将丢失。
请建议一种保持这些界限的方法。
提前感谢。您如何将其保存在核心数据中?@sschare我定义了一个类型为“Transformable”的列,使用
[nskeyedArchivedDataWithRootObject:historyText]
&[nskeyedUnarchiveObjectWithData:Data]
将边界重置为{{0,0},{0,0}}。使用NSRTFDTextDocumentType
或nshtmltexdocumenttype
尝试转换它们时,情况相同。似乎您的解决方案是使用EnumeratAttribute(\attrName:,在enumerationRange:,options中,使用block:)保存每个图像的边界。
不幸的是,此问题仍然存在。在取消归档时,边界仍然会重置为{{0,0},{0,0}}
。