开发者

Simple way to reading/writing NSAttributedString in iOS?

开发者 https://www.devze.com 2023-01-16 04:14 出处:网络
In Mac OS 开发者_如何学编程X, there is AppKit addition which supports reading and writing of NSAttributedString as RTF format.

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?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号