Problems with NSArray and iterators
Problems with NSArray and iterators
- Subject: Problems with NSArray and iterators
- From: Jarvis Cochrane <email@hidden>
- Date: Sat, 20 Aug 2005 10:45:27 +0800
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:
This email sent to email@hidden