• 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: Code Comments
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Code Comments


  • Subject: Re: Code Comments
  • From: Seth Willits <email@hidden>
  • Date: Sat, 08 Sep 2012 21:07:10 -0700

On Sep 8, 2012, at 8:00 PM, koko wrote:

> the m_xmlParserDelegate object is instanced in IB

Not a fan of instantiating objects in IB. Way too easy to get gigantic nibs going which ain't right.


> - (void)startMessageParse:(void*)msgStart end:(void*)msgEnd
> {
>    NSInteger length = msgEnd-msgStart+1;
>    if(length > 0 && length < 4096)

"the length check is arbitrary as I found without it I could get lengths that caused the dataWithBYtes to blow up"

Yeeeeaahh… your problem is elsewhere. dataWithBytes can certainly work with more than 4KB.




>    {
>        NSData *data = [NSData dataWithBytes:msgStart length:length];
>        if(data)

It's not going to fail.


>            NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithData:data];
>            [xmlParser setDelegate:m_xmlParserDelegate];
>            [xmlParser parse];
>            [data release];

Wrong. data was not alloc'd, create'd, copy'd, and was not retained by self so this an overrelease.



>            [xmlParser release];

Correct.






You're better of putting the NSData creation outside of this method where details of msgStart/msgEnd are better known, which would leave you with:


- (void)parseData:(NSData *)data
{
           NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithData:data];
           [xmlParser setDelegate:m_xmlParserDelegate];
           [xmlParser parse];
           [xmlParser release];
}



…but then one has to wonder why you need this method in this particular object. It's a bit awkward. I don't know what your delegate does exactly, particularly handling the results, but I would lean towards handing the data to the delegate object and telling it to parse it, rather than creating a parser here and setting the delegate.


--
Seth Willits





_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


References: 
 >Code Comments (From: koko <email@hidden>)

  • Prev by Date: Code Comments
  • Next by Date: Strange crash while loading nib
  • Previous by thread: Code Comments
  • Next by thread: Re: Code Comments
  • Index(es):
    • Date
    • Thread