www.delorie.com/gnu/docs/libobjects/libobjects_23.html   search  
 
Buy GNU books!


User's Guide to the GNU Objective-C Class Library

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

12.2 Basic Enumerating

The most basic enumerator is

Method: Collection @keyword{-withObjectsCall:} (void(*)(id))func
@deftypemethodx Collection {} @keyword{-safeWithObjectsCall:} (void(*)(id))func @deftypemethodx Collection {} @keyword{-withElementsCall:} (void(*)(elt))func @deftypemethodx Collection {} @keyword{-safeWithElementsCall:} (void(*)(elt))func Calls the function func with each the members of the collection. Returns self.

Method: Collection (void*) -newEnumState

Method: Collection -freeEnumState: (void**)enumStatePtr

Method: Collection (BOOL) -getNextObject: (id *)anObjectPtr @keyword{withEnumState:} (void**)enumState
@deftypemethodx {Collection} {(BOOL)} -getNextElement: (elt *)anElementPtr @keyword{withEnumState:} (void**)enumState

 
void print_first_difference (id coll1, id coll2)
  {
    void *enumState1, *enumState2;
    id object1, object2;

    enumState1 = [coll1 newEnumState];
    enumState2 = [coll2 newEnumState];
    while ([coll1 getNextObject:&object1 withEnumState:&enumState1]
           && [coll2 getNextObject:&object2 withEnumState:&enumState2])
      {
        if ([object1 compare:object2])
          {
            [object1 printForDebugger];
            [object2 printForDebugger];
          }
      }
    [coll1 freeEnumState:&enumState1];
    [coll2 freeEnumState:&enumState2];
  }

Method: Collection -withElementsCall: (void(*)(elt))aFunc @keyword{whileTrue:} (BOOL*)flag
@deftypemethodx {Collection} {} -safeWithElementsCall: (void(*)(elt))aFunc @keyword{whileTrue:} (BOOL*)flag


  webmaster   donations   bookstore     delorie software   privacy  
  Copyright © 2003   by The Free Software Foundation     Updated Jun 2003  

Please take a moment to fill out this visitor survey
You can help support this site by visiting the advertisers that sponsor it! (only once each, though)