这个有点奇怪 - 因为我知道它的规范答案。我预计会在 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/