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: Marcel Borsten <email@hidden>
- Date: Mon, 5 Nov 2007 20:43:30 +0100
Thank for your reply. It looks like you were right about me not
managing the life of the objects correctly. I had another look at that
part of the code and changed the sequence, now it works perfectly,
Thanks!
On 11/5/07, Marcel Borsten <email@hidden> wrote:
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.
When what happens? What it the stack trace at the time of the crash?
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'.
Consider using NSLog to help trace what is taking place however the
debugger is usually the best way. Are you sure you are using a debug
build of you application and stopping at a point in time that ensures
the vars you are interested in are valid (in scope).
For example try using the following code...
...
NSArray *myArray = [dict objectForKey: @"List"];
NSLog(@"myArray=%@", myArray);
firstNames = [NSMutableArray array];
int i, myNameList = [myArray count];
for ( i = 0; i < myNameList; i++ ) {
NSDictionary *nameEntry = [myArray objectAtIndex: i];
NSLog(@"nameEntry=%@", nameEntry);
NSString *name = [nameEntry valueForKey:@"name"];
NSLog(@"name=%@", name);
[firstNames addObject: name];
}
...
If the above logs what you expect then your problem is someplace
else... As a guess I would say you aren't managing the life of
firstNames correctly and it is disappearing before you get a chance to
update your view object with the data.
You don't list how you populate the NSPopupButton.
-Shawn
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