This one is a little odd - because I know the canonical answer to it. It's a problem that I'd expect to see on iOS (where NSAttributedString doesn't have initWithRTF), but I'm seeing it on Mac OS X at the moment.
The code is as follows:
+(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
}
As you can see, I expect a string to be returned if the code is compiled for Mac OS X, and nil to be returned for iOS (just because I haven't bothered putting the code in for iOS yet. I will. Eventually!)
For most of my projects, this code works perfectly - but on two of them (which are spotlight and quicklook importers) I get the error 'No visible @interface for 'NSAttributedString' declares the selector 'initWithRTF: documentAttributes:'
Furthermore, if I attempt to look up the documentation for this in Xcode it returns the iOS documentation for NSAttributedString, not the OS X documentation for NSAttributedString - suggesting that it thinks this plugin is for iOS. Checking the build settings however shows this project is set to OS X 10.10 with an architecture of 64-bit Intel and a supported platform of OS X.
What gives? Can anyone see my error?
You need to #import
the Cocoa or AppKit header file. Although NSAttributedString
is part of Foundation, the -initWithRTF:documentAttributes:
method is not. It's part of a category on NSAttributedString
in AppKit.