我在基于文档的应用程序中实现了保存和加载方法。在保存方法中,我有
[NSArchiver archivedDataWithRootObject:[self string]];
其中 [self string]
是一个 NSString。
当保存一个只有“普通内容”的文件时,创建的文件的内容是:
streamtypedè@NSStringNSObject+normal content
有没有办法将原始文本存储在文件中?
感谢您的帮助。
最佳答案
NSString 中有保存文件的方法:
NSString * s = @"Foo bar";
NSError * err = NULL;
BOOL result = [s writeToFile:@"/tmp/test.txt" atomically:YES encoding:NSASCIIStringEncoding error:&err];
关于Objective-c 保存原始文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1963569/