• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How To Design A Queue of Messages? [warning: complete source]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Re: How To Design A Queue of Messages? [warning: complete source] (From: Kins Collins <email@hidden>)

  • Prev by Date: Reading too many Files into Array returns Nil
  • Next by Date: Re: Is there a trick to NSTableViews?
  • Previous by thread: Re: How To Design A Queue of Messages? [warning: complete source]
  • Next by thread: indicating window is miniaturized
  • Index(es):
    • Date
    • Thread