• 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 deal with files
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: how to deal with files


  • Subject: RE: how to deal with files
  • From: "Jonathan E. Jackel" <email@hidden>
  • Date: Fri, 22 Nov 2002 14:07:03 -0500

Data is autoreleased when it is created. You did not use alloc, copy, or
new to create it, so you should not release it. When you release it anyway
at the end of WriteFile:, your program crashes.

Incidentally, I believe initWithCString is deprecated. There's no real
point to using a C string in this context anyway. Use

Path = [NSString stringWithString:@"/Users/pascal/Desktop/helpfile"]

Just remember the @. You could even do

Path = @"/Users/pascal/Desktop/helpfile"

Either way, get rid of [Path release].

Jonathan

> - (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@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: how to deal with files
      • From: Pascal Goguey <email@hidden>
References: 
 >how to deal with files (From: Pascal Goguey <email@hidden>)

  • Prev by Date: Re: more on stable sorting...
  • Next by Date: RE:Problems subclassing TextFields
  • Previous by thread: how to deal with files
  • Next by thread: Re: how to deal with files
  • Index(es):
    • Date
    • Thread