Simple way to reading/writing NSAttributedString in iOS?

不羁岁月 提交于 2019-12-07 07:57:13

问题


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

Equivalent in iOS? Should I make my own?


回答1:


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

To write an object to a file:

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

To read an object from a file:

attributedString = [NSKeyedUnarchiver unarchiveObjectWithFile:archivePath];

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



来源:https://stackoverflow.com/questions/3724985/simple-way-to-reading-writing-nsattributedstring-in-ios

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!