Re: Newbie OOP style question
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