I have a NSDictionary that contains multiple keys with the same name. Here is the structure:
Dictionary {
"Text" => "Blah",
"Text" => "Blah 2",
"Text" => "Blah 3"
}
So there are three keys with the same name Text. I put the values of Text into a NSMutableArray using:
NSDictionary *notes = [d objectForKey:@"notes"]; //dictionary above
NSMutableArray *notesA = [notes valueForKey:@"Text"];
NSLog(@"%i", notesA.count);
However, when I try to get the number of items in the array, it crashes with the following error:
-[__NSCFString count]: unrecognized selector sent to instance 0x856c110
Any idea why this is happening? I am able to output the values of the NSMutableArray and see them, but can’t count them.
Here is the XML file:
<tickets>
<text>Blah</text>
<text>Blah 2</text>
<text>Blah 3</text>
</tickets>
Notes dictionary output:
(
{
text = "Blah";
},
{
text = "Blah 1";
},
{
text = "Blah 2";
}
)
You are adding NSStrings as objects, not a NSArray.
As we are using a NSMutableArray, this would be valid too:
BTW:
This is not a valid NSDictionary structure, as keys have to be unique.
What you want is:
If you set several objetcs for the same key, the older object will be replaced by the newer.
When the parser parses the tickets tag, it should create a array which it uses to add the single texts.
Your notes object isnt a dictionary. it is an array with 3 dictionaries in it. each has an key text and some blah value.