NSArray

From GNUstepWiki
Revision as of 21:24, 16 February 2005 by Stefan Urbanek (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Well ... array.

Code chunks

Create index dictionary

Following method creates a dictionary which works as index by an attribute of contained objects.

- (NSDictionary *)indexDictionaryForKey:(NSString *)key
{
   NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
   NSDictionary        *retval;
   NSEnumerator        *enumerator;
   id                   object;

   enumerator = [self objectEnumerator];

   while( (object = [enumerator nextObject]) )
   {
       [dict setObject:object forKey:[object valueForKey:key]];
   }

   retval = [[NSDictionary alloc] initWithDictionary:dict];
   RELEASE(dict);
   
   return AUTORELEASE(retval);
}