Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6986241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:47:02+00:00 2026-05-27T18:47:02+00:00

I am new to both Cocoa programming and Xcode. I am wondering how I

  • 0

I am new to both Cocoa programming and Xcode. I am wondering how I can setenv (or set environment variable) using MainMenu.nib (or .xib) file. I have someone else’s code in the main function like this:

[NSApplication sharedApplication];
[NSBundle loadNibNamed:@"MainMenu" owner: NSApp];

After the second line, it can get an environment variable:

if (!getenv("R_HOME")) {
    fprintf(stderr, "R_HOME is not set.\n");
    return -1;
}

I want to know how one can construct a nib(or xib) file, e.g., MainMenu.xib, in Xcode 3’s latest version so that it can be used to setenv. One thing that I did was to code setenv without using a nib file:

setenv("R_HOME", "/Library/Frameworks/R.framework/Resources", 1)

But, this did not work when I execute the Cocoa GUI programming by double clicking the xxx.app although that worked when I execute the program’s command line version. So, it seems like that I need a way to set environment variables when a Mac GUI application is launched. I have seen other ways of setting environment variables, but I want to know how one can set environment variables using nib (or xib) files, and by loading it using NSBundle’s loadNibNamed method.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T18:47:03+00:00Added an answer on May 27, 2026 at 6:47 pm

    I want to know how one can construct a nib(or xib) file, e.g.,
    MainMenu.xib, in Xcode 3’s latest version so that it can be used to
    setenv.

    Nib files don’t have anything to do with environment variables. They don’t contain any code, and they have no impact on the program other than supplying data used to instantiate classes provided by the application’s code. I suppose you could write a class that sets environment variables and then use a nib to instantiate that class, but there’d be no difference between doing that and just instantiating the class in your code.

    One thing that I did was to code setenv without using a nib
    file:…But, this did not work when I execute the Cocoa GUI
    programming by double clicking the xxx.app although that worked when I
    execute the program’s command line version.

    How do you know it didn’t work? Are you calling getenv() to check the value of R_HOME in your code, or are you using a command like env in the terminal? If the latter, you’re not looking at the same environment where the variable was set.

    So, it seems like that I need a way to set environment variables when
    a Mac GUI application is launched.

    What are you trying to accomplish? It seems unlikely that you’d be setting an environment variable for your own program’s use — it already knows that value, so going out the environment seems pointless. Are you trying to communicate with another program?

    I have seen other ways of setting environment variables, but I want to
    know how one can set environment variables using nib (or xib) files,
    and by loading it using NSBundle’s loadNibNamed method.

    Again, there’s really no intersection between nib files and environment variables. If you want to be able to modify your app’s behavior based on some external variable, you can set environment variables in your .login file, and those values should be readable by your app. Perhaps a better solution would be to use the defaults system — your app can read and write values in the defaults system via NSUserDefaults, and you can read and write those same values at the command line using the defaults command.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm kinda new at both programming, and WPF. I know that this is pretty
I am new to programming. I am porting cpp (WIN32) to cocoa framework. I
OK, I'm still quite new to Xcode/Cocoa etc, so please forgive me if this
I'm new to both Ruby and programming in general. I've been trying to put
New to both Ruby and Rails but I'm book educated by now (which apparently
Being new to both WPF and MVVM, I'm studying Josh Smith's article on the
I'm new to both Web Services and RMI and I wonder which is the
I'm new to both ASP.Net MVC and jQuery and what I'm trying to do
I'm very new to both the Mvc framework as well as JavaScript and JQuery.
I'm new to both C# and Linq. I'm attempting to use a Linq-generated element

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.