2011-04-11 7 views
22

J'ai créé simple application Cocoa (Mac OS X 10.6) et sont apparus le point d'entrée:Cocoa: passer des arguments à NSApplicationDelegate

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

et AppDelegate mannequin:

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

et certains autre. Comment est-ce que je pourrais passer le argc et argv à mon AppDelegate bon chemin?

Répondre

31

Utiliser +[NSProcessInfo processInfo] et -[NSProcessInfo arguments].

Dans votre délégué de l'application,

- (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

merci, ça marche :) –