Where identifiers are defined, such as NSControlKeyMask

Where are ids such as NSControlKeyMask , NSAlternateKeyMask and NSShiftKeyMask ? I need to compile a Swift project using an Objective-C library called DDHotKey , which 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:

Using undeclared identifier 'NSControlKeyMask'

Using undeclared identifier 'NSAlternateKeyMask'

Using undeclared id "NSShiftKeyMask"

Why? What am I doing wrong? How can i fix this?

Thanks in advance.

+6
source share
1 answer

The DDHotKey example project uses a precompiled header file DDHotKey_Prefix.pch with the contents

 #ifdef __OBJC__ #import <Cocoa/Cocoa.h> #endif 

so <Cocoa/Cocoa.h> automatically included by all Objective-C sources. This, in turn, includes the foundation structure and AppKit headlines.

New Xcode projects no longer create precompiled header files. If you simply copied the source files from the sample project into a new project, your error will occur.

You can add a precompiled header file to your project, but actually it’s enough to add

 #import <AppKit/AppKit.h> 

in "DDHotKeyUtilities.m".

+9
source

Source: https://habr.com/ru/post/984561/


All Articles