[OGo-Developer] stuffing an NSArray into a NSMutableDictionary

Sebastian Reitenbach developer@opengroupware.org
Mon, 23 Apr 2007 20:42:57 +0200


Hi Rafel,

> 
> Can you trie the following code:
> 
> - (NSArray *)getQueues {
>   NSException *exc;
>   exc = [self sendCommand:@"QueueStatus"
>      withParameters:nil
>      expectResult:[[[self asteriskCommands]
>             objectForKey:@"QueueStatus"]
>                objectForKey:@"ExpectedResult"]];
>   if(exc) {
>     ASSIGN(self->lastException, exc);
>     return nil;
>   }
> 
>   NSEnumerator *e;
>   NSMutableDictionary *queuesdict;
>   id event;
>   queuesdict = [[NSMutableDictionary alloc] init];
> 
>   e = [self->multipleReturn objectEnumerator];
>   while ((event = [e nextObject]) != nil) {
>     if ([[event objectForKey:@"Event"] hasSuffix:@" QueueParams"]) {
>       NSMutableDictionary *tempdict;
>       NSMutableArray *temparray;
>       temparray = [[NSMutableArray alloc] init];
>       tempdict = [[NSMutableDictionary alloc] init];      
>       [tempdict addEntriesFromDictionary:event];
>       [tempdict setObject:[temparray retain] forKey:@"Agents"]; 
>       [queuesdict setObject:[tempdict retain] forKey:[event 
valueForKey:@"Queue"]];
>     } else {
>       NSMutableArray *temparray;
>       temparray = [[queuesdict objectForKey:[event objectForKey:@"Queue"] 
>                          objectForKey:@"Agents"];
>       [temparray addObject:event];
>     }
>   }
>   [self->multipleReturn release];
>   self->multipleReturn = nil;
>   self->multipleReturn = [[queuesdict allValues] retain];
>   return self->multipleReturn;
> }
> 
I had to change the 

      temparray = [[queuesdict objectForKey:[[event objectForKey:@"Queue"] 
                          objectForKey:@"Agents"]];

to let it compile, but then it ended up in an exception (Some 
NSConcrete8BitString does not recognize objectForKey) while running and I 
enter the AsteriskUI in OGo. Then I tried to replace my shuffling around 
with temporary variables where I put the queuesdict into the 
self->multipleReturn, your version:

   [self->multipleReturn release];
   self->multipleReturn = nil;
   self->multipleReturn = [[queuesdict allValues] retain];

mixed the array completely up, My webUI expects an array, and the 
repetitions made it looking funny ;) 
my version of it below, but just only for one queue:

    [queuesdict takeValue:[membersarray copy] forKey:@"Agents"];
    NSMutableArray *tmparray;
    tmparray = [[NSMutableArray alloc] init];
    [tmparray addObject:queuesdict];
    [self->multipleReturn removeAllObjects];
    ASSIGN(self->multipleReturn, [tmparray copy]);

nevertheless, thanks for taking time.

kind regards
Sebastian