macos - Mac OS X 上 NSAttributedString initWithRTF 没有可见接口(interface)

标签 macos cocoa quicklook spotlight

这个有点奇怪 - 因为我知道它的规范答案。我预计会在 iOS 上看到这个问题(其中 NSAttributedString 没有 initWithRTF),但目前我在 Mac OS X 上看到了它。

代码如下:

+(NSString*)stringFromRTFData:(NSData*)rtfData
{
    #if TARGET_OS_IPHONE
    return nil; //need to extract string from RTF for iOS
    #else
    NSAttributedString* intermediate = [[NSAttributedString alloc]initWithRTF:rtfData documentAttributes:nil];  
    return [intermediate string];
    #endif
}

正如你所看到的,如果代码是针对 Mac OS X 编译的,我希望返回一个字符串,而对于 iOS 则返回 nil (只是因为我还没有费心将代码放入 iOS 中。我会.最终!)

对于我的大多数项目,这段代码工作得很好 - 但在其中两个(聚光灯和快速查找导入器)上,我收到错误“没有可见的 @interface for 'NSAttributedString' 声明了选择器 'initWithRTF: documentAttributes:'

此外,如果我尝试在 Xcode 中查找相关文档,它会返回 NSAttributedString 的 iOS 文档,而不是 NSAttributedString 的 OS X 文档 - 这表明它认为该插件适用于 iOS。然而,检查build设置显示该项目设置为 OS X 10.10,具有 64 位 Intel 架构和受支持的 OS X 平台。

什么给了?谁能看到我的错误吗?

最佳答案

您需要#import Cocoa 或AppKit 头文件。虽然 NSAttributedString 是 Foundation 的一部分,但 -initWithRTF:documentAttributes: 方法不是。它是 AppKit 中 NSAttributedString 类别的一部分。

关于macos - Mac OS X 上 NSAttributedString initWithRTF 没有可见接口(interface),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27656343/

相关文章:

mysql - brew 和 mysql55 安装失败

mysql - 如何在 Mac OS Lion 上从命令行启动 MySQL 服务器?

macos - 代码设计 : What are unsealed contents?

ios - 检查 NSUnderlineStyle BitMask 的值

ios - 如何在基于 splitview 的 iPad 应用程序中快速查看文档

macos - .ssh/config : "Bad configuration option: UseKeychain" on Mac OS Sierra 10. 12.6

json - 我的数据正在写入 Firebase 数据库,但我无法读取它,为什么?

objective-c - 无法加载 nib 文件 : MainWindowController. xib,正在退出

macos - 有没有办法用 Applescript 触发 Finder 的 "quick look"窗口?

swift - 尝试预览文件时无法让 QuickLook 工作