0
votes

I know this has to be something super simple, but can't for the life of me figure it out. I can't get XCode to recognize NSWindow as an objective-c class. I have the following simple code:

HelloWorldAppDelegate.h

#import  <Cocoa/Cocoa.h>
#import "EAGLView_mac.h"

@interface HelloWorldAppDelegate : NSObject <NSApplicationDelegate> {
    NSWindow    *window;
    EAGLView    *glView;
}

@property (assign) IBOutlet NSWindow    *window;
@property (assign) IBOutlet EAGLView    *glView;

@end

HelloWorldAppDelegate.m

#import "HelloWorldAppDelegate.h"
#import "EAGLView_mac.h"

@implementation HelloWorldAppDelegate
@synthesize window, glView;

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
    NSRect frame = NSMakeRect(0, 0, 480, 320);

    window = [[NSWindow alloc] initWithContentRect: frame styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:YES];

    //EAGL init code cut for brevity      

    [window setContent:glView];
    [window makeKeyAndOrderFront:self];
}

@end

When I try to compile XCode complains that NSWindow is a receiver type 'void' and not an objective-c class. None of the autocomplete functions popped up when I was typing up the code either. I get an actual error on the call to NSWindow alloc, and a warning on the other two calls to 'window' all complaining that window and/or NSWindow is a receiver type void. It also complains that the methods 'setContent' and 'makeKeyAndOrderFront' are not found? Am I missing an include somewhere?

1
If you create a brand new Cocoa App project with all of the default settings, does it have the same problem? If so, it's possible that your AppKit framework (either the one in /System/Library or the one in one of the Xcode SDKs) is broken… but I'd start by reinstalling Xcode and see if that works.abarnert

1 Answers

0
votes

Try changing the property attribute of the NSWindow and EAGLView outlets to either

  • (nonatomic, retain), if you're not using ARC
  • (weak), if you're using ARC

The Objective-C Programming Language: Declared Properties explains this and states:

assign
Specifies that the setter uses simple assignment. This attribute is the default. You use this attribute for scalar types such as NSInteger and CGRect.

Hope this helps.