• 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: writeToFile and arrayWithContentsOfFile
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: writeToFile and arrayWithContentsOfFile


  • Subject: Re: writeToFile and arrayWithContentsOfFile
  • From: Bryan Blackburn <email@hidden>
  • Date: Wed, 15 Jan 2003 02:15:10 -0700
  • Mail-followup-to: email@hidden

This is due to the fact that those types of methods (arrayWith, stringWith,
etc) are not alloc or copy methods. The alloc and copy methods will
return objects which you are responsible for releasing, while others
will return autoreleased objects. Your line could also be

PhoneBookData = [[NSMutableArray alloc]
initWithContentsOfFile:[@"~/PhoneBackup.txt
"stringByStandardizingPath]];

with the same end result (and probably is a little better on the logic side).
Check out

http://www.stepwise.com/Articles/Technical/2001-03-11.01.html

Bryan


On Jan 15, 2003 00:46, Chuck Rice stated:
> >arrayWithContentsOfFile: returns an autoreleased object, so if you need to
> >use the results later (which I'm guessing you are since you're loading
> >it into an object variable), you'll need to retain it:
> >
> > PhoneBookData = [[NSMutableArray
> >arrayWithContentsOfFile:[@"~/PhoneBackup.txt
> >"stringByStandardizingPath]] retain];
>
>
>
> That was it! Thanks. Looking at the doc:
>
> >arrayWithContentsOfFile:
> >
> >+ (id)arrayWithContentsOfFile:(NSString *)aPath
> >
> >Creates and returns an array containing the contents of the file
> >specified by aPath. The file identified by aPath must contain a
> >string representation produced by the writeToFile:atomically:
> >method. In addition, the array representation must contain only
> >property list objects (NSString, NSData, NSArray, or NSDictionary
> >objects).
> >
> >Returns nil if the file can't be opened or if the contents of the
> >file can't be parsed into an array.
> >
> >See Also: - writeToFile:atomically:
>
>
> How do I know that it is an autoreleased object? Am I looking at the
> wrong doc? -Chuck-
> _______________________________________________
> 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.
_______________________________________________
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.

References: 
 >Custom bundle extension (From: Mark Levin <email@hidden>)
 >writeToFile and arrayWithContentsOfFile (From: Chuck Rice <email@hidden>)
 >Re: writeToFile and arrayWithContentsOfFile (From: Bryan Blackburn <email@hidden>)
 >Re: writeToFile and arrayWithContentsOfFile (From: Chuck Rice <email@hidden>)

  • Prev by Date: Atomic operations in Obj-C?
  • Next by Date: Re: coding struct with keyed archivers
  • Previous by thread: Re: writeToFile and arrayWithContentsOfFile
  • Next by thread: Re: Converting an NSScrollView decendant to NSView
  • Index(es):
    • Date
    • Thread