在iOS中读写NSAttributedString的简单方法?

4
在Mac OS X中,有一个名为AppKit的附加组件,支持将NSAttributedString作为RTF格式进行读写。
在iOS中是否有相应的功能?我需要自己制作吗?
1个回答

4

你只是想将字符串保存到磁盘上吗?我建议使用NSCoding。

将对象写入文件的方法:

result = [NSKeyedArchiver archiveRootObject:attributedString toFile:archivePath];

从文件中读取一个对象的方法是:
attributedString = [NSKeyedUnarchiver unarchiveObjectWithFile:archivePath];

您可以使用符合“NSCoding”的任何对象来实现此操作,并且向您自己的类添加对NSCoding的支持相当容易。更多信息可在以下网址找到:http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Archiving/Archiving.html%23//apple_ref/doc/uid/10000047-SW1

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接