Skip navigation.
 
mlRE: how to deal with files
FROM : Marco Binder
DATE : Fri Nov 22 18:35:28 2002

Dont release Data... as far as I can see, your quite familiar with
cocoas retain/release mechanism. You probably just forgot, that
"convenience methods" (like most class methods) return an autoreleased
instance. So does [NSData dataWithBytes:]...

marco


Am Freitag, 22.11.02 um 17:52 Uhr schrieb Pascal Goguey:

> Hello,
>
> I am new to Cocoa, and I am trying to figure out how to work with
> files. I wrote a simple test. One GUI with a single button. One object
> (see below). The button calls the method WriteFile, and that's
> about it.
> Everytime I push the button (the only one), it should write one
> line at the end of the file. The code of the object is listed below.
> The problem is that the program exits after the first button press.
>
> Any hint?
>
> Thanks,
>
> Pascal
>
>
> ---------------
> /* FileObject */
>
> #import <Cocoa/Cocoa.h>
>
> @interface FileObject : NSObject {
>      IBOutlet id mWriteButton;
>     NSFileHandle * mFileHandle;
> }
> - (IBAction)WriteFile:(id)sender;
>
> @end
> ---------------
> #import "FileObject.h"
>
> @implementation FileObject
>
> - (void)awakeFromNib {
>     mFileHandle = NULL;
> }
>
> - (IBAction)WriteFile:(id)sender {
>     NSString * Path = [[NSString alloc]
> initWithCString:"/Users/pascal/Desktop/helpfile"];
>     NSData * Data = [NSData dataWithBytes:"help!\n" length:6];
>     //    Create the file object if it does not exist yet
>     if(mFileHandle == NULL) {
>         //    Check if the file itself exists at the specified path. If not,
> create it
>         NSFileManager * mFileManager = [NSFileManager defaultManager];
>         if([mFileManager fileExistsAtPath: Path] == NO) {
>             [mFileManager createFileAtPath:Path contents:nil attributes:nil];
>         }
>         //  Then at this point, the file exists physically on the disk
>         mFileHandle = [NSFileHandle fileHandleForUpdatingAtPath:Path];
>     }
>     [mFileHandle seekToEndOfFile];
>     [mFileHandle writeData:Data];
>     [mFileHandle closeFile];
>     [mFileHandle release];
>     mFileHandle = NULL;
>     [Path release];
>     [Data release];
> }
>
> @end
> _______________________________________________
> cocoa-dev mailing list | <email_removed>
> Help/Unsubscribe/Archives:
> http://www.lists.apple.com/mailman/listinfo/cocoa-dev
> Do not post admin requests to the list. They will be ignored.
>
>

--
|\  /|      E-Mail: <email_removed>  WWW: www.marco-binder.de
| \/ |        Telefon: 07531 / 94 19 94  Fax: 07531 / 94 19 92
|    |ARCO        Snail-Mail: Banater Str. 3 - 78467 Konstanz
      BINDER _____________________________________________________
_______________________________________________
cocoa-dev mailing list | <email_removed>
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

Related mailsAuthorDate
mlhow to deal with files Pascal Goguey Nov 22, 17:52
mlRE: how to deal with files Marco Binder Nov 22, 18:35
mlRE: how to deal with files Jonathan E. Jackel Nov 22, 20:07
mlRe: how to deal with files Pascal Goguey Nov 23, 00:15