Where are identifiers like NSControlKeyMask
, NSAlternateKeyMask
and NSShiftKeyMask
defined? I need to compile Swift project using Objective-C library named DDHotKey that contains the following code:
if (modifiers & NSControlKeyMask) {
[final appendString:[characterMap objectForKey:@(kVK_Control)]];
}
if (modifiers & NSAlternateKeyMask) {
[final appendString:[characterMap objectForKey:@(kVK_Option)]];
}
if (modifiers & NSShiftKeyMask) {
[final appendString:[characterMap objectForKey:@(kVK_Shift)]];
}
This code gives me the following errors:
Use of undeclared identifier 'NSControlKeyMask'
Use of undeclared identifier 'NSAlternateKeyMask'
Use of undeclared identifier 'NSShiftKeyMask'
Why? What am I doing wrong? How can I fix it?
Thanks in advance.
The "DDHotKey" sample project uses a precompiled header file "DDHotKey_Prefix.pch" with the contents
#ifdef __OBJC__
#import <Cocoa/Cocoa.h>
#endif
so that <Cocoa/Cocoa.h>
is automatically included by all Objective-C
sources. This in turn includes the Foundation and AppKit framework
headers.
New Xcode projects do not create precompiled headers files anymore. If you just copied the sources files from the sample project to a new project, your error will occur.
You could add a precompiled header file to your project, but it actually seems to be sufficient to add
#import <AppKit/AppKit.h>
in "DDHotKeyUtilities.m".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With