Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The best solution usually is to move this kind of logic into a model object like <code>MYConfiguration</code>. That way you can query <code>MYConfiguration</code> with explicit methods, and never directly access the <code>NSDictionary</code>.</p> <p>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).</p> <p>First is the constant. In <code>MYConfiguration.m</code>, you can put a private constant like this:</p> <pre><code>static NSString * const kConfigurationFileBaseName = @"Config"; </code></pre> <p>You can also have a method that returns the path:</p> <pre><code>- (NSString *)pathToConfigurationFile { return [[NSBundle mainBundle] pathForResource:kConfigurationFileBaseName ofType:@"plist"]; } </code></pre> <p>It's not uncommon to hard-code the name of the file directly in <code>pathToConfigurationFile</code> rather than having a constant. Constants <em>often</em> 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 <em>guidelines</em>, not rules.</p> <p>If you need the constant itself to be publicly available, then you declare it this way in <code>MYConfiguration.h</code>:</p> <pre><code>extern NSString * const kMYConfigurationFileBaseName; </code></pre> <p>and then define it in .m:</p> <pre><code>NSString * const kMYConfigurationFileBaseName = @"Config"; </code></pre> <p>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.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload