Какао: передать аргументы NSApplicationDelegate - PullRequest
22 голосов
/ 11 апреля 2011

Я создал простое приложение Cocoa (Mac OS X 10.6) и там появилась точка входа:

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

и AppDelegate пустышка:

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

и некоторые другие. Как я мог передать argc и argv на мой AppDelegate правильный путь?

1 Ответ

31 голосов
/ 11 апреля 2011

Используйте +[NSProcessInfo processInfo] и -[NSProcessInfo arguments].

В вашем приложении делегат,

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