2011-04-11 21 views
22

He creado la aplicación Cocoa sencilla (Mac OS X 10.6) y no ha aparecido el punto de entrada:Cacao: pasar argumentos a NSApplicationDelegate

int main(int argc, char *argv[]) 
{ 
    return NSApplicationMain(argc, (const char **) argv); 
} 

y AppDelegate dummy:

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification 
{ 
    // how to get argc and argv? 
} 

y algunos otro. ¿Cómo podría pasar el argc y argv a mi AppDelegate de la manera correcta?

Respuesta

31

Utilice +[NSProcessInfo processInfo] y -[NSProcessInfo arguments].

En su delegado aplicación,

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification 
{ 
    NSArray *args = [[NSProcessInfo processInfo] arguments]; 
    // use -objectAtIndex: to obtain an element of the array 
    // and -count to obtain the number of elements in the array 
} 
+0

gracias, funciona :) –

Cuestiones relacionadas