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. Howe
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.
int main() {
[NSAutoreleasePool new];
[NSApplication sharedApplication];
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
id menubar = [[NSMenu new] autorelease];
id appMenuItem = [[NSMenuItem new] autorelease];
[menubar addItem:appMenuItem];
[NSApp setMainMenu:menubar];
id appMenu = [[NSMenu new] autorelease];
id appName = [[NSProcessInfo processInfo] processName];
id quitTitle = [@"Quit " stringByAppendingString:appName];
id quitMenuItem = [[[NSMenuItem alloc] initWithTitle:quitTitle
action:@selector(terminate:) keyEquivalent:@"q"] autorelease];
[appMenu addItem:quitMenuItem];
[appMenuItem setSubmenu:appMenu];
id window = [[[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 200, 200)
styleMask:NSTitledWindowMask backing:NSBackingStoreBuffered defer:NO]
autorelease];
[window cascadeTopLeftFromPoint:NSMakePoint(20,20)];
[window setTitle:appName];
[window makeKeyAndOrderFront:nil];
[NSApp activateIgnoringOtherApps:YES];
[NSApp run];
return 0;
}
Of course, it's too late to answer on this but for anyone who is thinking on creating iOS App without Xib(Nib) files should keep this thing in mind.
Note: Although you can create an Objective-C application without using nib files, doing so is very rare and not recommended. Depending on your application, avoiding nib files might require you to replace large amounts of framework behavior to achieve the same results you would get using a nib file.
See this Documentation to know more what apple has to say on this approach
I hope this could help someone in future. Thanks!
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.
Though this is a few years old question...
Here's minimal code snippet to bootstrap a Cocoa application in Swift.
import AppKit
final class ExampleApplicationController: NSObject, NSApplicationDelegate {
let window1 = NSWindow()
func applicationDidFinishLaunching(aNotification: NSNotification) {
window1.setFrame(CGRect(x: 0, y: 0, width: 800, height: 500), display: true)
window1.makeKeyAndOrderFront(self)
}
func applicationWillTerminate(aNotification: NSNotification) {
}
}
autoreleasepool { () -> () in
let app1 = NSApplication.sharedApplication()
let con1 = ExampleApplicationController()
app1.delegate = con1
app1.run()
}
Also, I am maintaining a bunch of programmatic examples for Cocoa including bootstrapping, window, menu creations.
See subprojects for desired language.