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 7518149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:40:24+00:00 2026-05-30T01:40:24+00:00

What would you consider best practice to store constants (like file names for property

  • 0

What would you consider best practice to store constants (like file names for property lists) in objective-c?

I would like to improve the hard coded “Config.plist” in the following code:

NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"Config" ofType:@"plist"];
NSDictionary *rows = [[NSDictionary alloc]initWithContentsOfFile:plistPath];
  • 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-30T01:40:26+00:00Added an answer on May 30, 2026 at 1:40 am

    The best solution usually is to move this kind of logic into a model object like MYConfiguration. That way you can query MYConfiguration with explicit methods, and never directly access the NSDictionary.

    Regarding the name of that file, there are many approaches to abstracting it, depending on how much reuse you really need (it is possible to go overboard here).

    First is the constant. In MYConfiguration.m, you can put a private constant like this:

    static NSString * const kConfigurationFileBaseName = @"Config";
    

    You can also have a method that returns the path:

    - (NSString *)pathToConfigurationFile {
      return [[NSBundle mainBundle] pathForResource:kConfigurationFileBaseName ofType:@"plist"];
    }
    

    It’s not uncommon to hard-code the name of the file directly in pathToConfigurationFile rather than having a constant. Constants often are only needed in cases where the value is used more than once. If a given constant only appears one time, then moving the value elsewhere can sometimes make the code harder to understand. These are just guidelines, not rules.

    If you need the constant itself to be publicly available, then you declare it this way in MYConfiguration.h:

    extern NSString * const kMYConfigurationFileBaseName;
    

    and then define it in .m:

    NSString * const kMYConfigurationFileBaseName = @"Config";
    

    But the key in all of this is that you define these constants in a header related to the use of the constant. You don’t create some central “MYGlobals” dumping ground for everything.

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

Sidebar

Related Questions

Would you consider it bad practice to store various user data in a database
What would you consider best practice for organizing JUnit tests in a project, and
Consider a disk file containing 100 records a. How many comparisons would be required
I am new to Perforce. What would you consider P4 best practices in terms
What's considered best practice writing OOP classes when it comes to using a property
What do you consider best practice when it comes to error handling errors in
So I would consider myself a .Net and ASP.NET pro but I am a
I have what I would consider a small sized iPhone app that uses SQLite.
Consider the Java code below, what would happen if there were no paintComponent method
Consider: var object = { foo: {}, bar: {}, baz: {} } How would

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.