Objective-c 保存原始文本
我在基于文档的应用程序中实现了保存和加载方法。在保存方法中,我有
[NSArchiver archivedDataWithRootObject:[self string]];
Where [self string]
is a NSString。 当保存仅包含“正常内容”的文件时,创建的文件的内容为:
streamtypedè@NSStringNSObject+普通内容
有没有办法在文件中仅存储原始文本?
感谢您的帮助。
I implemented saving and loading methods in my document-based application. In the saving method, I have
[NSArchiver archivedDataWithRootObject:[self string]];
Where [self string]
is a NSString.
When saving a file with just "normal content" inside of it, the contents of the file created are:
streamtypedè@NSStringNSObject+normal content
Is there a way to store in a file just raw text?
Thanks for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
NSString 内部有一些方法用于保存在文件中:
There are methods inside NSString for saving in a file:
由于我是可可新手,我不知道这是否是正确的方法,甚至是有效的方法。
但快速查看文档后,我发现了 NSString 实例的这种方法,
- (NSData *)dataUsingEncoding:(NSStringEncoding)encoding
快速尝试了一个示例项目,它运行良好:
- (NSData *)dataOfType:(NSString *)typeName error:(NSError **)outError
所以这样的东西可能适合你:
Since i am new with cocoa, i don't know if this is the right way to do it or even a valid way.
But after a quick look at the documentation i found this method of NSString instances,
- (NSData *)dataUsingEncoding:(NSStringEncoding)encoding
A quick try on a sample project it worked fine with:
- (NSData *)dataOfType:(NSString *)typeName error:(NSError **)outError
So something like this might work for you: