• 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: NSArray init with a path
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSArray init with a path


  • Subject: Re: NSArray init with a path
  • From: "John C. Randolph" <email@hidden>
  • Date: Thu, 21 Jun 2001 15:22:21 -0700

On Thursday, June 21, 2001, at 12:10 PM, Jason Brown wrote:

Ok, given a file setup like the following:

<array>
<string> string information here </string>
<string> more info </string>
.
.
.
<string> last one </string>
</array>


I had hoped that the following code would work: (given that masterList is NSArray type and the file does exist at that location)

NSString *dataPath = [NSHomeDirectory()
stringByAppendingPathComponent:@"Documents/books.dat"];

masterList = [[NSArray alloc] initWithContentsOfFile:dataPath];

Since this doesnt work, I am obviously missing something. Is there a better way to format the file? Is there a different init method I should use?

The method you want is -propertyList.

Pull the file contents into a string first, like so:

NSString *contents = [NSString stringWithContentsOfFile:dataPath];
NSArray *masterList = [[contents propertyList] retain];


Secondary question, is there any equivalent method to NSHomeDirectory() that would return the path to the directory that the app is running in? Ala NSAppDirectory()?

NSString *appLocation = [[NSBundle mainBundle] path];

-jcr

"This is not a book to be tossed aside lightly. Rather, it should be hurled with great force." -Dorothy Parker


References: 
 >NSArray init with a path (From: Jason Brown <email@hidden>)

  • Prev by Date: Re: Filling arguments for AuthorizationExecuteWithPrivileges (very newbie)
  • Next by Date: Re: WWDC Dev Tools / Software update
  • Previous by thread: Re: NSArray init with a path
  • Next by thread: Sorry for email problems...
  • Index(es):
    • Date
    • Thread