Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where are identifiers like NSControlKeyMask defined

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.

like image 864
FrozenHeart Avatar asked Apr 01 '15 14:04

FrozenHeart


1 Answers

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".

like image 65
Martin R Avatar answered Oct 18 '22 02:10

Martin R