[OGo-Developer] stuffing an NSArray into a NSMutableDictionary
Rafel Amer Ramon
developer@opengroupware.org
Wed, 18 Apr 2007 10:28:22 +0200
This is a multi-part message in MIME format.
--------------070703030004000202040501
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
En/na Sebastian Reitenbach ha escrit:
> Hi Rafel,
>
>
>> can you send an example of the initial values of self->multipleReturn
>> and the desired final values?
>>
>>
>
> my initial array looks like this:
>
> Apr 17 14:14:57 ogo-webui-1.1 [23380]: self->multipleReturn: (
> {
> Abandoned = " 0";
> Calls = " 0";
> Completed = " 0";
> Event = " QueueParams";
> Holdtime = " 0";
> Max = " 0";
> Queue = " l00-bugdead-prods-queue";
> ServiceLevel = " 0";
> ServicelevelPerf = " 0.0";
> Weight = " 0";
> }, etc...
> I am not sure whether an array is the best choice to store the queues in it,
> but at least it fits best with the rest of the OGoAsteriskUI that is working
> so far. So I am open for any suggestion, I'd also drop the idea to store it
> in a array and use a dictionary instead...
>
> kind regards
> Sebastian
>
>
Sebastian,
I think the followin code must work:
- (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;
NSMutableArray *membersarray;
id event;
queuesdict = [[NSMutableDictionary alloc] initWithCapacity:8];
membersarray = [[NSMutableArray alloc] initWithCapacity:8];
e = [self->multipleReturn objectEnumerator];
while ((event = [e nextObject]) != nil) {
if ([[event objectForKey:@"Event"] hasSuffix:@" QueueParams"]) {
[queuesdict addEntriesFromDictionary:event];
} else {
[membersarray addObject:event];
}
}
[queuesdict setObject:[membersarray retain] forKey:@"Agents"];
[self->multipleReturn release];
self->multipleReturn = [ [NSMutableArray arrayWithObject:queuesdict]
retain];
return self->multipleReturn;
}
In fact, the final value of self->multipleReturn is an array with only
one element,
a dictionary. If you need that self->multipleReturn must be an array, I
think that's ok,
but it also could be a dictionary or a variable of type id initially
containing an array
and finally containing a dictionary.
Kind regards,
Rafel.
--
Aquest missatge ha estat analitzat per MailScanner
a la cerca de virus i d'altres continguts perillosos,
i es considera que està net.
For all your IT requirements visit: http://www.transtec.co.uk
--------------070703030004000202040501
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
En/na Sebastian Reitenbach ha escrit:
<blockquote cite="mid20070417124508.E4FE33B62C@l00-bugdead-prods.de"
type="cite">
<pre wrap="">Hi Rafel,
</pre>
<blockquote type="cite">
<pre wrap="">can you send an example of the initial values of self->multipleReturn
and the desired final values?
</pre>
</blockquote>
<pre wrap=""><!---->
my initial array looks like this:
Apr 17 14:14:57 ogo-webui-1.1 [23380]: self->multipleReturn: (
{
Abandoned = " 0";
Calls = " 0";
Completed = " 0";
Event = " QueueParams";
Holdtime = " 0";
Max = " 0";
Queue = " l00-bugdead-prods-queue";
ServiceLevel = " 0";
ServicelevelPerf = " 0.0";
Weight = " 0";
}, etc...
I am not sure whether an array is the best choice to store the queues in it,
but at least it fits best with the rest of the OGoAsteriskUI that is working
so far. So I am open for any suggestion, I'd also drop the idea to store it
in a array and use a dictionary instead...
kind regards
Sebastian
</pre>
</blockquote>
<br>
<br>
Sebastian,<br>
<br>
I think the followin code must work:<br>
<br>
- (NSArray *)getQueues {<br>
NSException *exc;<br>
exc = [self sendCommand:@"QueueStatus"<br>
withParameters:nil<br>
expectResult:[[[self asteriskCommands] <br>
objectForKey:@"QueueStatus"] <br>
objectForKey:@"ExpectedResult"]];<br>
if(exc) {<br>
ASSIGN(self->lastException, exc);<br>
return nil;<br>
}<br>
<br>
NSEnumerator *e;<br>
NSMutableDictionary *queuesdict;<br>
NSMutableArray *membersarray;<br>
id event;<br>
<br>
queuesdict = [[NSMutableDictionary alloc] initWithCapacity:8];<br>
membersarray = [[NSMutableArray alloc] initWithCapacity:8];<br>
<br>
e = [self->multipleReturn objectEnumerator];<br>
while ((event = [e nextObject]) != nil) {<br>
if ([[event objectForKey:@"Event"] hasSuffix:@" QueueParams"]) {<br>
[queuesdict addEntriesFromDictionary:event];<br>
} else {<br>
[membersarray addObject:event];<br>
}<br>
}<br>
[queuesdict setObject:[membersarray retain] forKey:@"Agents"];<br>
[self->multipleReturn release];<br>
self->multipleReturn = [ [NSMutableArray
arrayWithObject:queuesdict] retain];<br>
return self->multipleReturn;<br>
}<br>
<br>
<br>
In fact, the final value of self->multipleReturn is an array with
only one element,<br>
a dictionary. If you need that self->multipleReturn must be an
array, I think that's ok,<br>
but it also could be a dictionary or a variable of type id initially
containing an array <br>
and finally containing a dictionary.<br>
<br>
<pre wrap="">Kind regards,
Rafel.
</pre>
<br>
<br>
</body>
<br />--
<br />Aquest missatge ha estat analitzat per
<a href="http://www.mailscanner.info/"><b>MailScanner</b></a>
<br />a la cerca de virus i d'altres continguts perillosos,
<br />i es considera que está net.
<br />MailScanner agraeix a <a href="http://www.transtec.co.uk/">transtec Computers</a> pel seu suport.
</html>
--------------070703030004000202040501--