本文介绍了在iOS中读/写NSAttributedString的简单方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Mac OS X中,还有AppKit添加,它支持以RTF格式读取和写入NSAttributedString。

In Mac OS X, there is AppKit addition which supports reading and writing of NSAttributedString as RTF format.

在iOS中等效?我应该自己动手吗?

Equivalent in iOS? Should I make my own?

推荐答案

您是否只想将字符串保存到磁盘?我会使用NSCoding。

Do you just want to save the string to the disk? I would use NSCoding for that.

将对象写入文件:

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

从文件中读取对象:

attributedString = [NSKeyedUnarchiver unarchiveObjectWithFile:archivePath];

您可以使用符合NSCoding的任何对象执行此操作,并且可以非常轻松地添加对NSCoding到您自己的课程。有关更多信息,请访问:

You can do this with any object conforming to "NSCoding", and it's fairly easy to add support for NSCoding to your own classes. More information can be found at:

这篇关于在iOS中读/写NSAttributedString的简单方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-20 20:48