Re: How To Design A Queue of Messages? [warning: complete source]
Re: How To Design A Queue of Messages? [warning: complete source]
- Subject: Re: How To Design A Queue of Messages? [warning: complete source]
- From: Chris Hanson <email@hidden>
- Date: Mon, 12 Sep 2005 22:31:11 -0700
Kins, just a couple of minor tips about your code.
On Sep 12, 2005, at 4:38 PM, Kins Collins wrote:
- (id)pop
{
id firstItem = [theQueue objectAtIndex:0];
[theQueue removeObjectAtIndex:0];
return firstItem;
}
Just FYI, before assigning to firstItem you should retain the result
of -objectAtIndex: since the object at that index may have no other
retainers beyond your mutable array. Then you should return the
result of autoreleasing the object in firstItem, to preserve the
general Cocoa API contract.
- (void)print
{
int i;
NSLog(@"\n");
for (i=0; i<[self size]; i++)
NSLog([theQueue objectAtIndex:i]);
NSLog(@"\n");
}
Rather than implementing your own -print method, you should generally
override -[NSObject description] to return this information as an
NSString. This allows you to specify one of your Queue objects as a %
@ parameter to NSLog or to anything that invokes -[NSString
initWithFormat:].
-- Chris
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden