我想保存我的UItextview'text的attributesString。 我試圖轉換爲字符串並保存。但是當我回到設置text'attributedString時,它不起作用。如何將NSAttributedString保存到CoreData
這是我如何轉換成字符串:
var a = String(stringInterpolationSegment: text.attributedText)
Data.setValue(a, forKey: "font")
Data.managedObjectContext?.save(nil)
我這是怎麼回設置:
text.attributedText = NSAttributedString(string: size)
但我的TextView只顯示AttributedSting
{
NSFont = "<UICTFont: 0x7fa9fa82aec0> font-family: \"Helvetica Neue\"; font-weight: normal; font-style: normal; font-size: 18.00pt";
NSParagraphStyle = "Alignment 0, LineSpacing 0, ParagraphSpacing 0, ParagraphSpacingBefore 0, HeadIndent 0, TailIndent 0, FirstLineHeadIndent 0, LineHeight 0/0, LineHeightMultiple 0, LineBreakMode 0, Tabs (\n 28L,\n 56L,\n 84L,\n 112L,\n 140L,\n 168L,\n 196L,\n 224L,\n 252L,\n 280L,\n 308L,\n 336L\n), DefaultTabInterval 0, Blocks (null), Lists (null), BaseWritingDirection -1, HyphenationFactor 0, TighteningFactor 0, HeaderLevel 0";
}
我很抱歉,我無法發佈圖片。我使用swift來做到這一點。
我的問題:我該怎麼做?或者有另一種方法來保存歸屬文本?
[存儲NSAttributedString核心數據]的可能的重複(http://stackoverflow.com/questions/4266226/storing-nsattributedstring-core-data) –
@i_am_jorf這個問題我以前讀過,它是用object-cI寫的不知道如何做到這一點 –
請參考由i_am_jorf在鏈接中的pob21的答案。這不是公認的答案,但它是正確的做法。我在我的應用程序中使用相同的方法(使用Swift)。 –