Why is Xcode Giving Me These Errors?

喜欢而已 提交于 2019-12-11 18:03:02

问题


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

回答1:


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.




回答2:


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.




回答3:


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



来源:https://stackoverflow.com/questions/1072822/why-is-xcode-giving-me-these-errors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!