NSDocument读取RTFD数据
我正在开发一个文本编辑器,我想添加 RTFD 支持。将 RTFD 文件类型添加到 Info.plist 后,我收到消息“readFromFileWrapper:ofType:error: 必须覆盖您的应用程序才能处理文件包”。
我浏览了文档并发现了一些东西,但我没能完成所有事情..有人可以这么好心帮助我吗?
- (BOOL)readFromFileWrapper:(NSFileWrapper *)fileWrapper ofType:(NSString *)typeName error:(NSError **)outError {
if ([typeName isEqualToString:@"Rich Text with Attachments"]) {
NSLog(@"Its RTFD");
//it gets to here but I don't know how to load the rtfd data then :(
}
ofType:typeName] return YES; }
感谢任何帮助:)
I am working on a text editor and I want to add RTFD support. After adding the RTFD file type to my Info.plist, I got the message that "readFromFileWrapper:ofType:error: must be overridden for your application to handle file packages."
I had a look around in the documentation and found some things, but I didn't manage to do everything..Could someone be so kind and help me out please?
- (BOOL)readFromFileWrapper:(NSFileWrapper *)fileWrapper ofType:(NSString *)typeName error:(NSError **)outError {
if ([typeName isEqualToString:@"Rich Text with Attachments"]) {
NSLog(@"Its RTFD");
//it gets to here but I don't know how to load the rtfd data then :(
}
ofType:typeName] return YES; }
Any help is apprechiated :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
幸运的是,RTFD 是一种特别简单的方法。查看
NSText
的readRTFDFromFile:
和writeRTFDToFile:atomically:
方法。来自 NSText 类参考< /a>:
如果您来自
NSURL
,请执行以下操作:为了安全起见,请先调用
[[self url] isFileURL]
。RTFD is a particularly easy one, luckily. Check out the
readRTFDFromFile:
andwriteRTFDToFile:atomically:
methods ofNSText
.From the NSText Class Reference:
If you're coming from
NSURL
, do something like this:To be safe, call
[[self url] isFileURL]
first.我尝试了您的代码片段并实现了以下目标:
NSDocument 窗口已打开,标题已更新为 RTFD 文件的名称,但 NSTextView 仍为空白。
我非常确信我的代码会打开它,因为我从 NSDocument 实例获取了 URL,将其转换为 NSString 并将其发送到文本视图...
日志返回了以下内容:
那么它应该可以工作吗?
I tried your snippet and achieved the following:
The NSDocument window was opened, the title was updated to the RTFD file's name but the NSTextView is still blank.
I was pretty convinced that my code would open it, since I got myself the URL from the NSDocument instance, converted it to an NSString and sent it to the textview...
The Log returned this:
So it should work?