Run NSRunLoop in a Cocoa command-line program

前端 未结 6 1684
遥遥无期
遥遥无期 2020-11-27 04:20

Is it possible to initialize a NSRunLoop without loading any NIB files (i.e., without calling NSApplicationMain())?

Thanks.

6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-27 04:45

    The solution is to invoke NSApplication manually. Create your app delegate first than replace the NSApplicationMain() call in main.m with the following:

    AppDelegate * delegate = [[AppDelegate alloc] init];
    
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    
    NSApplication * application = [NSApplication sharedApplication];
    [application setDelegate:delegate];
    [NSApp run];
    
    [pool drain];
    
    [delegate release];
    

    The delegate will be invoked when ready, without needing a nib

    - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
    

提交回复
热议问题