Getting the right objects in an Array
Getting the right objects in an Array
- Subject: Getting the right objects in an Array
- From: Marcel Borsten <email@hidden>
- Date: Mon, 5 Nov 2007 18:59:39 +0100
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
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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