Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Getting the command line in Objective-C


Recommended Posts

I'm trying to grab the arguments to the main function and pass them onto the C++ application. I am not very well-versed in Obj-C. What am I doing wrong here?:

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
    // Insert code here to initialize your application
    NSArray* args = [[NSProcessInfo processInfo] arguments];
    std::vector<const char*> arr (args.count);
    for (int n = 0; n < args.count; ++n)
    {
        NSString* s = args[n];
        auto cs = [s UTF8String];
        arr.push_back(cs);
    }
    mymain(int(arr.size()), arr.data());
}

 

Link to post
Share on other sites

Got it:

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
    // Insert code here to initialize your application
    int argc = *_NSGetArgc();
    char** argv = *_NSGetArgv();
    mymain(argc, (const char**)argv);
}

 

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...