[OGo-Developer] stuffing an NSArray into a NSMutableDictionary

Helge Hess developer@opengroupware.org
Mon, 16 Apr 2007 10:08:51 +0200


On Apr 16, 2007, at 09:04, Sebastian Reitenbach wrote:
> Adding the list of queues to the dict is no problem. but when I try  
> to add
> the Agents array to each Queue, it is just doing working. I tried a  
> lot of
> variations, one is shown below, but I do not get it to store it in  
> there,
> must be some stupid thing I am just doing wrong ;)
>
>   else {
>     /* need to sort the output in multiple */
>     NSEnumerator *e;
>     NSMutableDictionary *tmpdict;
>     id event;
>     tmpdict = [[NSMutableDictionary alloc] init];
>     e = [self->multipleReturn objectEnumerator];
>     while ((event = [e nextObject])) {
>       if ([[event objectForKey:@"Event"] hasSuffix:@" QueueParams"]) {
>         /* the queue description, their parameters */
>         [tmpdict takeValue:event forKey:[event  
> objectForKey:@"Queue"]];
>       } else {
>         /* queue members */
>         if ([[tmpdict objectForKey:[event objectForKey:@"Queue"]]
> objectForKey:@"Agents"] == nil) {
>           [[tmpdict objectForKey:[event objectForKey:@"Queue"]]  
> takeValue:
> [[NSMutableArray alloc] init] forKey:@"Agents"];
>         }
>         [[[tmpdict objectForKey:[event objectForKey:@"Queue"]]
> objectForKey:@"Agents"]
>                 addObject:event];
>       }
>     }
>
> any hint is very appreciated.

Can't read the code. I suppose you need to start up in the debugger  
(or insert NSLogs) and see whats happening?


Stuff like that is a memory leak:

   [[tmpdict objectForKey:[event objectForKey:@"Queue"]] takeValue:
     [[NSMutableArray alloc] init] forKey:@"Agents"]

The array will never get released.

If you know that you are working on a property list  
(NSMutableDictionary), you might want to use -setObject:forKey:  
instead of -takeValue:forKey:, though it should do the same thing (if  
it *is* a dictionary).

Greets,
   Helge
-- 
Helge Hess
http://www.helgehess.eu/