在iOS中读/写NSAttributedString的简单方法? [英] Simple way to reading/writing NSAttributedString in iOS?

查看:126
本文介绍了在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:

http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Archiving/Archiving.html% 23 // apple_ref / doc / uid / 10000047-SW1

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆