Re: Problems with NSArray and iterators
Re: Problems with NSArray and iterators
- Subject: Re: Problems with NSArray and iterators
- From: David Teran <email@hidden>
- Date: Sat, 20 Aug 2005 14:12:05 +0200
Hi,
i've had the same problem with the Iterator from NSArray (WO 5.3).
Its buggy and you should switch to ERXMutableArray which also
implements list or if you cannot switch to ERXMutableArray from
NSArray 'cause you get the NSArray from a relationship accessor
method then you must prevent the Iterator as its buggy...
regards, David
On 20.08.2005, at 04:45, Jarvis Cochrane wrote:
Hello!
This has been driving me nuts for a while, and I was wondering if
anyone else had seen the same behaviour.
I'm finding that the java.util.Iterator and java.util.Enumerator
returned from NSArray.iterator() and NSArray.objectEnumerator()
contain "Null" values.
This code will fail:
java.util.Iterator iterator = assignedClients().iterator();
while (iterator.hasNext()) {
Client child = (Client)iterator.next();
child.someMethod(); /* child
is sometimes null and throws an exception */
}
But this works:
java.util.Iterator iterator = assignedClients().iterator();
while (iterator.hasNext()) {
Client child = (Client)iterator.next();
if (child!=null)
child.someMethod();
}
And turning the NSArray into a Vector, and using Vector.iterator()
also works - thus:
java.util.Iterator iterator = assignedClients().vector().iterator();
while (iterator.hasNext()) {
Client child = (Client)iterator.next();
child.someMethod();
}
AssignedClients(), btw is an EOGenerator generated getter for a one-
to-many relationship in my EOModel:
public NSArray assignedClients() {
return (NSArray)storedValueForKey("assignedClients");
}
Soooo.... assignedClients().iterator() contains some null values,
but assignedClients().vector().iterator() doesn't?
I must be missing something!
Thanks in advance,
Jarvis
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40cluster9.com
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden