Re: Saving a NSMutableArray into a plain ASCII file
Re: Saving a NSMutableArray into a plain ASCII file
- Subject: Re: Saving a NSMutableArray into a plain ASCII file
- From: Phillip Morelock <email@hidden>
- Date: Tue, 28 May 2002 15:18:04 -0700
This may be a bit of a hack, but could you use a loop with objectEnumerator?
This is how I would do it in Java or C++.
Open this in internet explorer:
file://localhost/System/Library/Frameworks/Foundation.framework/Versions/C/R
esources/English.lproj/Documentation/Reference/ObjC_classic/Classes/NSArray.
html#//apple_ref/occ/instm/NSArray/objectEnumerator
Use a loop with the objectEnumerator and append the lines like so:
(pseudo-code, not really objective c)
-----------
NSEnumerator *enum = [myArray objectEnumerator]
while ( local_variable = [enum nextObject] )
{
mystring += (cast to string type if necessary) local_variable
mystring += LF character
}
writeToFile: aFile contents: mystring
---------
just an idea...
fillup
On 5/28/02 2:48 PM, "Frank Blome" <email@hidden> wrote:
>
Hello again,
>
>
First of all I like to thank you all fellows here on the list, I never had
>
found a resource where Iearned so much in a really short time. With every
>
day I come closer and closer to the concepts of the Cocoa framework and
>
learn how to read it (the documentation is IMHO not really the easiest one
>
;-) Therefore: THANK YOU GUYS! Hopefully in the near future I can help you
>
at some issues :-)
>
>
I like to save the contents of a NSMutableArray into a file. My method
>
therefore is:
>
>
- (IBAction) saveFile:(id)sender
>
{
>
NSString *configFile;
>
configFile = [NSString stringWithString:@"~/myfile.txt"];
>
configFile = [configFile stringByExpandingTildeInPath];
>
[contents writeToFile:configFile atomically:YES];
>
}
>
>
This works fine, but the result is a XML-Format, which is obviously right,
>
since "contents" is an Array. But I need the file back in a standard UNIX
>
format (linefeed at the end and so on). Unfortunately I did not found any
>
method in the documentation which put my Array (actually a NSMutableArray)
>
into a NSString. I search for this method, because I believe this is the
>
way to save it. If not, feel free to advise me.
>
>
Another point is the header of the column in a NSTableView. I found in the
>
documentation, that I have to use "setTitle" to give the header a NSString.
>
But unfortunately I can't manage it.
>
>
Frank
>
_______________________________________________
>
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.