• 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: Newbie OOP style question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Newbie OOP style question


  • Subject: Re: Newbie OOP style question
  • From: Duncan Anker <email@hidden>
  • Date: Fri, 12 May 2006 10:09:21 +1000

Hi Tim,

@interface FileObject: NSObject
{
    NSNumber *fileLength;
    NSData *dataBuffer;
    unsigned long numBuffer;
}

-(void) setFileLengthWithFile: (NSFileHandle *) fileHandle;

@end

@implementation FileObject
-(void) setFileLengthWithFile: (NSFileHandle *) fileHandle
{
    dataBuffer = [fileHandle readDataOfLength:4];
    [dataBuffer getBytes: &numBuffer];
    numBuffer = EndianU32_LtoN(numBuffer);
    fileLength = [NSNumber numberWithUnsignedLong: numBuffer];
}
You need to retain fileLength or it will get cleaned up sometime later. Objects given you by convenience routines are autoreleased, so if you want to keep them you must do it explicitly. You would also need to add a dealloc method to your object so you can release the NSNumber when you are done.

As far as the tempory variables go, if you are only using numBuffer locally to the setFileLengthWithFile method, you should declare it locally rather than in the class interface.

HTH,
Duncan
_______________________________________________
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: 
 >Newbie OOP style question (From: "Tim Gray" <email@hidden>)

  • Prev by Date: WebServicesCore and Serialization of NULL
  • Next by Date: Re: Newbie OOP style question
  • Previous by thread: Newbie OOP style question
  • Next by thread: Re: Newbie OOP style question
  • Index(es):
    • Date
    • Thread