Reputation: 17916
I'm working on an extension of Core Data functionality. I've got a block of code where I'd like to test if a user's NSApplicationDelegate
implements the templated managedObjectContext
accessor. But I don't want to require the AppKit framework or NSApplication
(I might use the functionality in command-line applications), so I'd like to wrap the block in an #ifdef
.
Looking at NSApplication.h, there are #define
s for NSAppKit versions (e.g. NSAppKitVersionNumber10_0
). I could test for an arbitrary one of those, but that doesn't feel quite right. Is there a generic way in the preprocessor to test whether the current compilation environment includes a framework or specific header?
Upvotes: 0
Views: 125
Reputation: 237080
No, there is not, because:
The test for an AppKit version is the idiomatic way to do this sort of thing in the preprocessor.
However, i don't see why you need the preprocessor for this.
BOOL delegateImplementsAccessor = [[[NSClassFromString(@"NSApplication") sharedApplication] delegate] respondsToSelector:@selector(managedObjectContext)];
Upvotes: 1