views:

184

answers:

4

Yes, I know this goes against the whole MVC principle!

However, I'm just trying to whip up a pretty trivial application - and I've pretty much implemented it pragmatically. However, I have a problem...

I create an Empty Project, copy all the frameworks over and set the build settings - and I get errors about the executable.. or lack of executable. The build settings all appear fine, but it tells me there is no executable - it will build + run fine.. however it doesn't run. There is no error either - it just appears to run very fast and cleanly! Unless I try and run gdb which politely tells me I need to give it a file first..

Running…  
No executable file specified.  
Use the "file" or "exec-file" command.

So I created a Cocoa Application, removed all the stuff I didn't need (i.e the MainMenu.xib file..) and now I can compile my code perfectly.. however it dies with complaining that its

"Unable to load nib file: MainMenu, exiting"

I have gone through the Project Symbols and see that the code actually relies upon the nib file heavily, even if you don't touch it code-wise. (MVC again I guess..)

So my question is - is there a simple way to compile just what you code, no added nib files, just the code you write and the frameworks you add? I assume it would be a blank project but my experience tells me otherwise?!

+2  A: 

The problem might be that you're still calling NSApplicationMain in your main function (in main.m). If you're not loading a nib such as MainMenu.nib, you'll probably have to rip out the call to NSApplicationMain and write your own code in main for starting the application.

mipadi
I expected to do that actually, but I think NSApplicationMain must just take the .nib info from the .plist file - as it seems to be running fine! Cheers for the quick reply though!
Moddy
For the record - there was still one or two issues I hadn't noticed until I had re-implemented NSApplication! So you were both right, cheers again. (Incase anyone was wondering -" [NSApplication shareApplication] "- followed by -" [NSApp run "- was enough to fix the final errors)
Moddy
+1  A: 

Of course you can write just code and not use Interface Builder.

Have you checked your Info.plist? By default there is an entry there for MainMenu.xib and it may be that reference it's complaining about.

slf
I hadn't touched Interface Builder! Thats what bugged me, removing the entry from the Info.plist has resolved this - thanks! Was a really speedy reply! :D
Moddy
A: 

Don't use NSApplication and NSApp... You just have to specify your class which implement the UIApplicationDelegate protocol : UIApplicationMain(argc, argv, nil, @"Name of your class");

tata
A: 

Hi there, this is the method i use in my applications. Sorry for the formatting, i hope you can make it out. I don’t know how to turn off the auto-formatting here.

Of course there will be no functioning main menu out of this example, that’s far too much code for me to write on a post like this :P - Sorry, out do some research on that ;)

This should get you started:

AppDelegate.h

@interface MyApplicationDelegate : NSObject {

NSWindow * window;

}

@end

AppDelegate.m

@implementation MyApplicationDelegate : NSObject

  • (id)init {

    if (self = [super init]) { // allocate and initialize window and stuff here .. } return self; }

  • (void)applicationWillFinishLaunching(NSNotification *)notification {

    [window makeKeyAndOrderFront:self]; }

  • (void)dealloc {

    [window release];

    [super dealloc]; }

@end

main.m

import “AppDelegate.h”

int main(int argc, char * argv[]) {

NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSApplication * application = [NSApplication sharedApplication];

MyApplicationDelegate * appDelegate = [[[[MyApplicationDelegate]alloc] init] autorelease];

[application setDelegate:appDelegate];
[application run];

[pool drain];

return EXIT_SUCCESS;

}

Casper B. Hansen