首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将NSMutableAttributedString写/读到Plist

将NSMutableAttributedString写/读到Plist
EN

Stack Overflow用户
提问于 2012-09-10 16:50:47
回答 1查看 924关注 0票数 3

好的,我们在这里:

  • 我有个NSTextView
  • 我得到的是NSMutableAttributedString的内容
  • 我不能把它读/写到plist

通过使用Rob的代码( Saving custom attributes in NSAttributedString ),我已经取得了一些进展(我正在设法将数据写入磁盘),但我无法恢复它(= NSKeyedUnarchiver返回nil)。

编码:

代码语言:javascript
复制
// where MAS --> NSMutableAttributedString

NSData* stringData = [NSKeyedArchiver archivedDataWithRootObject:MAS];

解码:

代码语言:javascript
复制
NSMutableAttributedString* mas = (NSMutableAttributedString*)[NSKeyedUnarchiver unarchiveObjectWithData:dat];

有什么想法吗?任何可能的解决办法(即使不是使用NSCoder,我怀疑它适用于RTF.)会受到欢迎的!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-09-10 17:56:37

这是如何被解决的。

NSAttributedString ->

代码语言:javascript
复制
NSData* j = [(NSMutableAttributedString*)MAS RTFDFromRange:NSMakeRange(0,[[MAS string] length]) 
                                        documentAttributes:nil];

NSData -> NSAttributedString

代码语言:javascript
复制
NSMutableAttributedString* mas = [[NSMutableAttributedString alloc] initWithRTFD:dat 
                                                              documentAttributes:nil];

就这么简单。

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12356134

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档