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

  • SEARCH
  • Home
  • 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 6326175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:02:24+00:00 2026-05-24T17:02:24+00:00

Most of the models in my iOS app query a web server. I would

  • 0

Most of the models in my iOS app query a web server. I would like to have a configuration file storing the base URL of the server. It will look something like this:

// production
// static NSString* const baseUrl = "http://website.example/"

// testing
static NSString* const baseUrl = "http://192.168.0.123/"

By commenting out one line or the other, I can instantly change which server my models point to. My question is, what’s the best practice for storing global constants in iOS? In Android programming, we have this built-in strings resource file. In any Activity (the equivalent of a UIViewController), we can retrieve those string constants with:

String string = this.getString(R.string.someConstant);

I was wondering if the iOS SDK has an analogous place to store constants. If not, what is the best practice in Objective-C to do so?

  • 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-24T17:02:27+00:00Added an answer on May 24, 2026 at 5:02 pm

    You could also do a

    #define kBaseURL @"http://192.168.0.123/"
    

    in a "constants" header file, say constants.h. Then do

    #include "constants.h"
    

    at the top of every file where you need this constant.

    This way, you can switch between servers depending on compiler flags, as in:

    #ifdef DEBUG
        #define kBaseURL @"http://192.168.0.123/"
    #else
        #define kBaseURL @"http://myproductionserver.example/"
    #endif
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Where do most Rails apps usually keep their non-active-record classes? In app/models? In lib/some_file.rb?
Most of the ASP.NET MVC paging solutions I have found by googling look like
I have updated_by field in most of my models. I need to update this
I am working on a web app based on Flask and SQLAlchemy. Most of
What are the most web-capable mobile phones to date (models and / or user
Most games come with their resources (models, textures, etc.) packed into special files (like
I noticed most 3d voxel models are actually pretty low resolution, but then are
Most of us write conditionals like: if (resultIndex == 0) ...but occaisionally I come
I have a model in App Engine that I am exporting in CSV format
I have some models all linked together in memory (parent:child:child:child) and saved at the

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.