Note that there are some explanatory texts on larger screens.

plurals
  1. POAccessing Plist Arrays / Nodes - Objective C
    primarykey
    data
    text
    <p>I have a Property List file that I'm using to store questions and answer data. Within this file I have a collection of arrays, within these I store the different categories and questions. However I can't seem to access this data?</p> <p>The property file;</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;Category1&lt;/key&gt; &lt;array&gt; &lt;array&gt; &lt;string&gt;Question1&lt;/string&gt; &lt;string&gt;Answer1&lt;/string&gt; &lt;/array&gt; &lt;array&gt; &lt;string&gt;Question2&lt;/string&gt; &lt;string&gt;Answer2&lt;/string&gt; &lt;/array&gt; &lt;array&gt; &lt;string&gt;Question3&lt;/string&gt; &lt;string&gt;Answer3&lt;/string&gt; &lt;/array&gt; &lt;array&gt; &lt;string&gt;Question4&lt;/string&gt; &lt;string&gt;Answer4&lt;/string&gt; &lt;/array&gt; &lt;/array&gt; &lt;/dict&gt; &lt;/plist&gt; </code></pre> <p>Below I'm using to access the property list file by stepping through it using two simple buttons;</p> <pre><code>-(IBAction)nextleft { [self bingsound]; if (questionCounter &gt; 1) { questionCounter -= 1; } [self nextQuestion]; } -(IBAction)nextright { [self bingsound]; if (questionCounter &lt; 20) { questionCounter += 1; } [self nextQuestion]; } -(void)nextQuestion { NSArray *pair; pair = [categories objectAtIndex:questionCounter]; plistQuestion = [pair objectAtIndex:0]; plistAnswer = [pair objectAtIndex:1]; abbreviation.text = plistQuestion; } </code></pre> <p>I'm populating the the category array as follows;</p> <pre><code>categories = [NSArray arrayWithContentsOfFile:@"questions.plist"]; </code></pre>
    singulars
    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.
 

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