Skip navigation.
 
mlRe: Getting the right objects in an Array
FROM : Paul Goracke
DATE : Mon Nov 05 20:24:08 2007

I don't know about wrong, but you are making it difficult on yourself. 
Assuming your 'dict' is the property list dictionary, you should be 
able to simply say

   firstNames = [NSMutableArray arrayWithArray:[dict 
valueForKeyPath:@"List.name"]];

pg


On Nov 5, 2007, at 9:59 AM, Marcel Borsten wrote:

> Hello everybody,
>
> I hope someone can help me with the following; I'm trying to use a 
> plist to fill a NSPopupbutton menu item with strings from the plist. 
> The plist looks as follows:
>
>
> <?xml version="1.0" encoding="UTF-8"?>
>    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd
> ">
>    <plist version='1.0'>
>            <dict>
>                    <key>List</key>
>                    <array>
>                            <dict>
>                                    <key>name</key>
>                                    <string>Joe</string>
>                                    <key>uuid</key>
>                                     
> <string>A4640553-1C93-4FCD-98FE-917AF1700C6B</string>
>                            </dict>
>                            <dict>
>                                    <key>name</key>
>                                    <string>Jane</string>
>                                    <key>uuid</key>
>                                    <string>B6DBECAC-3472-4692-
> B0FC-6143A46A7B53</string>
>                            </dict>
>                    </array>
>            </dict>
>    </plist>
>
>
> I'm using the following code to fill a NSMutableArray with strings 
> from the NSDictionary object. The for loop gets the instances of the 
> keys 'name' and puts the string in the mutable array object 
> 'firstNames'. In my program it uses the firstNames-array to fill a 
> NSPopupButton with the Array of NSStrings. When that happens the 
> program exits with a “EXC_BAD_ACCESS”-error. It looks to me that the 
> objects in the returned mutable array are not NSString objects. When 
> I debug, Xcode shows my NSString-value as 'invalid'.
> .....
>
>     NSArray *myArray = [dict objectForKey: @"List"];    
>     firstNames = [NSMutableArray array];
>     
>     int i, myNameList = [myArray count];
>     
>     for ( i = 0; i < myNameList; i++ )    {
>
>         NSDictionary *nameEntry = [myArray objectAtIndex: i];
>         
>         NSString *myName;
>         myName = [[NSString alloc] initWithString: [nameEntry valueForKey: 
> @"name"]];
>
>         [firstNames addObject: myName];
>
>     }
>         
>     return firstNames;    
> .....
>
> Can anybody give me some clues on what I'm doing horribly wrong 
> here? Thanks,
>
> Marcel

Related mailsAuthorDate
mlGetting the right objects in an Array Marcel Borsten Nov 5, 18:59
mlRe: Getting the right objects in an Array Shawn Erickson Nov 5, 19:37
mlRe: Getting the right objects in an Array Paul Goracke Nov 5, 20:24
mlRe: Getting the right objects in an Array Marcel Borsten Nov 5, 20:43