Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do you create and access array elements in settings bundle
    text
    copied!<p>I want to save strings as array elements in a Settings.bundle Root.plist and be able to access those strings from the Setting bundle on subsequent launches of my app. I could not find a good example of this anywhere. In xcode, I have created the Root.plist and it looks something like:</p> <pre><code>Key iPhone Setting Schema Strings Filename Preference Items Item 0 (Title- My Title) Type Title Title My Title Identifier My Identifier Values Item 0 my string 1 Item 1 my string 2 Item 3 my string 3 </code></pre> <p>This produces xml as follows:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt; &lt;plist version="1.0"&gt; &lt;dict&gt; &lt;key&gt;StringsTable&lt;/key&gt; &lt;string&gt;Root&lt;/string&gt; &lt;key&gt;PreferenceSpecifiers&lt;/key&gt; &lt;array&gt; &lt;dict&gt; &lt;key&gt;Type&lt;/key&gt; &lt;string&gt;PSTitleValueSpecifier&lt;/string&gt; &lt;key&gt;Title&lt;/key&gt; &lt;string&gt;My Title&lt;/string&gt; &lt;key&gt;Key&lt;/key&gt; &lt;string&gt;My Identifier&lt;/string&gt; &lt;key&gt;Values&lt;/key&gt; &lt;array&gt; &lt;string&gt;my string 1&lt;/string&gt; &lt;string&gt;my string 2&lt;/string&gt; &lt;string&gt;my string 3&lt;/string&gt; &lt;/array&gt; &lt;/dict&gt; </code></pre> <p>I am using the following code to attempt an access of the Values from the Identifier key "My Identifier":</p> <pre><code>NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; NSArray *mystrings = [defaults arrayForKey:@"My Identifier"]; for (int i=0;i&lt;3;i++) { NSLog(@"%@", [mystrings objectAtIndex:i]); } </code></pre> <p>The value of mystrings is 0 at runtime. Consequently, the Values of "my string 1", "my string 2", and "my string 3" are not getting printed by the NSLog.</p> <p>Can someone help me with this. Also, what would be the correct way to update those values?</p>
 

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