FROM : Mike Abdullah
DATE : Mon Aug 14 21:21:08 2006
Let's say I have an NSArray of several hundred instances of
MyObject. MyObject has a simple accessor method:
- (long)objectID;
I want to find the instance of MyObject whose objectID is 204. What
would be the best way of doing this? At present, the only thing I
can really think of is:
NSEnumerator *objectsEnumerator = [myArray objectEnumerator];
MyObject *anObject;
while (anObject = [objectsEnumerator nextObject])
{
if ([anObject objectID] == 204)
return anObject;
}
However this seems a little clunky. Is there a better way of doing
things in Cocoa that I haven't come across?
Mike.
DATE : Mon Aug 14 21:21:08 2006
Let's say I have an NSArray of several hundred instances of
MyObject. MyObject has a simple accessor method:
- (long)objectID;
I want to find the instance of MyObject whose objectID is 204. What
would be the best way of doing this? At present, the only thing I
can really think of is:
NSEnumerator *objectsEnumerator = [myArray objectEnumerator];
MyObject *anObject;
while (anObject = [objectsEnumerator nextObject])
{
if ([anObject objectID] == 204)
return anObject;
}
However this seems a little clunky. Is there a better way of doing
things in Cocoa that I haven't come across?
Mike.
| Related mails | Author | Date |
|---|---|---|
| Mike Abdullah | Aug 14, 21:21 | |
| Greg Hurrell | Aug 14, 21:50 | |
| wbyoung | Aug 15, 00:04 | |
| Mike Abdullah | Aug 28, 23:26 |






Cocoa mail archive

