Next: 3.4 Fun with NSMenuItem's Up: 3 Menus Previous: 3.2 Setting the Application

3.3 Our First Application

We are ready now to create our first gui application:
#include <Foundation/Foundation.h>
#include <AppKit/AppKit.h>

@interface MyDelegate : NSObject
- (void) applicationWillFinishLaunching: (NSNotification *)not;

@implementation MyDelegate : NSObject 
- (void) applicationWillFinishLaunching: (NSNotification *)not
  NSMenu *menu;
  menu = AUTORELEASE ([NSMenu new]);
  [menu addItemWithTitle: @"Quit"  
        action: @selector (terminate:)  
        keyEquivalent: @"q"];
  [NSApp setMainMenu: menu];

int main (int argc, const char **argv)
  [NSApplication sharedApplication];
  [NSApp setDelegate: [MyDelegate new]];

  return NSApplicationMain (argc, argv);
Put this code for example into a file called MyApp.m, and use the following GNUmakefile for it:
include $(GNUSTEP_MAKEFILES)/common.make

APP_NAME = MyFirstApp
MyFirstApp_OBJC_FILES = MyApp.m 

# Uncomment the following if you have an icon
#MyFirstApp_APPLICATION_ICON = MyApp.png
#MyFirstApp_RESOURCE_FILES = MyApp.png

include $(GNUSTEP_MAKEFILES)/application.make
Compile it, then run it using openapp ./ (see the GNUmakefile mini-tutorial for further information on writing GNUmakefiles).