Question

The error I get is Xcode saying 3 things are un-declared (see below picture) alt text http://snapplr.com/snap/ks4h

But in the Header File I have declared them (see below picture)

alt text http://snapplr.com/snap/htmb

Why I am getting these errors when I have declared them.

The Full Code:

Header File.

#import <Foundation/Foundation.h>


@interface HotKeyController : NSObject {
    IBOutlet NSButton *cmdHK;
    IBOutlet NSButton *ctrHK;
    IBOutlet NSButton *optHK;
    IBOutlet NSPopUpButton *keyHK;
    IBOutlet NSWindow *window;
    IBOutlet NSWindow *searchWindow;
    IBOutlet NSWindow *entryWindow;
}

@end

Implementation File

#import "HotKeyController.h"
#include <Carbon/Carbon.h>

@implementation HotKeyController

OSStatus MyHotKeyHandler(EventHandlerCallRef nextHandler,EventRef theEvent,void *userData)
{
    EventHotKeyID hkCom;
    GetEventParameter(theEvent,kEventParamDirectObject,typeEventHotKeyID,NULL,sizeof(hkCom),NULL,&hkCom);
    int l = hkCom.id;

    switch (l) {
        case 1: [window makeKeyAndOrderFront:NSApp];  
            break;
        case 2: [searchWindow makeKeyAndOrderFront:nil];
            break;
        case 3: [entryWindow makeKeyAndOrderFront:nil];
            break;  
    }
    return noErr;
}

- (void)awakeFromNib
{
    //Register the Hotkeys
    EventHotKeyRef gMyHotKeyRef;
    EventHotKeyID gMyHotKeyID;
    EventTypeSpec eventType;
    eventType.eventClass=kEventClassKeyboard;
    eventType.eventKind=kEventHotKeyPressed;


    InstallApplicationEventHandler(&MyHotKeyHandler,1,&eventType,pl,NULL);

    gMyHotKeyID.signature='htk1';
    gMyHotKeyID.id=1;
    if([[NSUserDefaults standardUserDefaults] integerForKey:@"hotkeyShowMain"]!=-999) {
        RegisterEventHotKey([[NSUserDefaults standardUserDefaults] integerForKey:@"hotkeyShowMain"], [[NSUserDefaults standardUserDefaults] integerForKey:@"hotkeyShowMainModifier"], gMyHotKeyID, GetApplicationEventTarget(), 0, &gMyHotKeyRef);
    }

    gMyHotKeyID.signature='htk2';
    gMyHotKeyID.id=2;
    if([[NSUserDefaults standardUserDefaults] integerForKey:@"hotkeyShowSearch"]!=-999) {
        RegisterEventHotKey([[NSUserDefaults standardUserDefaults] integerForKey:@"hotkeyShowSearch"], [[NSUserDefaults standardUserDefaults] integerForKey:@"hotkeyShowSearchModifier"], gMyHotKeyID, GetApplicationEventTarget(), 0, &gMyHotKeyRef);
    }

    gMyHotKeyID.signature='htk3';
    gMyHotKeyID.id=3;
    if([[NSUserDefaults standardUserDefaults] integerForKey:@"hotkeyShowEntry"]!=-999) {
        RegisterEventHotKey([[NSUserDefaults standardUserDefaults] integerForKey:@"hotkeyShowEntry"], [[NSUserDefaults standardUserDefaults] integerForKey:@"hotkeyShowEntryModifiers"], gMyHotKeyID, GetApplicationEventTarget(), 0, &gMyHotKeyRef);
    }

}

@end
Was it helpful?

Solution

You would have to show more of the file to be sure. Are you properly importing the header file? Have you saved the header file?

Try inserting the explicit self-> references and you might get a more revealing error message.

Also, try preprocessing the implementation file (in the Build menu) and that might reveal why the ivar isn't being found.

OTHER TIPS

The error I get is Xcode saying 3 things are un-declared …

But in the Header File I have declared them …

Why I am getting these errors when I have declared them [in the HotKeyController class].

Because those lines are in a function, not in a method of the HotKeyController class. It doesn't matter where you put the function (inside @implementation or not); it's still a function, not a method.

How would I make the userData parameter point to my HotKeyController?

You set that when you create the event handler. In fact, you're already setting it to “pl”, whatever that is.

NSWindow is not defined in the Foundation framework, you must import the right headers, ApplicationKit or Cocoa.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top