Re: Getting the right objects in an Array
Re: Getting the right objects in an Array
- Subject: Re: Getting the right objects in an Array
- From: Paul Goracke <email@hidden>
- Date: Mon, 5 Nov 2007 11:24:08 -0800
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
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden